2013-08-09 13 views
5

TabbarControllerでViewControllerをプッシュするにはどうすればいいですか? ViewController'XIBで、私はUITabbarControllerを作成しました。それから、このViewControllerをプッシュしますが、UITabbarControllerは表示されません。 これは私のコードです: * Viewcontroller.h:iOsのUIViewControllerにUITabbarControllerを追加するには

@interface StatusViewController : UIViewController<UITabBarControllerDelegate> 
{ 
    IBOutlet UITabBarController *tabBarController; 

    IBOutlet UIButton *UploadButton; 
    IBOutlet UIButton *ConvertorButton; 
    IBOutlet UIButton *CompletedButton; 
} 
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; 
@end 

* Viewcontroller.m:あなたの助けを

@implementation StatusViewController 
@synthesize tabBarController ; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 

    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    [self createTabView]; 
} 
-(void)createTabView 
{ 
    .... 

    .... 
    [ConvertorButton addSubview:Label3]; 

    [CompletedButton setTag:3]; 


    [CompletedButton setImage:[UIImage imageNamed:@"Overlay-2.png"] forState:UIControlStateNormal]; 
    [CompletedButton setImage:[UIImage imageNamed:@"background.jpg"] forState:UIControlStateSelected]; 
    [CompletedButton setImage:[UIImage imageNamed:@"background.jpg"] forState:UIControlStateHighlighted]; 

    //[[CompletedButton layer] setBorderWidth:2.0f]; 
    // [[CompletedButton layer] setBorderColor:[UIColor grayColor].CGColor]; 

    UILabel *Label4=[[UILabel alloc]initWithFrame:CGRectMake(6, 8, 70, 30)]; 
    [Label4 setTextAlignment:UITextAlignmentCenter]; 
    [Label4 setText:@"Completed"]; 


    Label4.backgroundColor=[UIColor clearColor]; 
    [Label4 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]]; 
    Label4.textColor=[UIColor whiteColor]; 
    [CompletedButton addSubview:Label4]; 

    // [self selectTab:1]; 

    [self.view addSubview:UploadButton]; 

    [self.view addSubview:ConvertorButton]; 

    [self.view addSubview:CompletedButton]; 


} 

おかげ

+0

ここで提示した質問は理解できません.Plzそれを適切にしますか? –

+0

あなたはあなたのrootviewを動的に変更することができます。何がUITabbarcontollerを押す必要があります – Vinodh

答えて

9

のサンプルコードです...

のUIViewControllerの.hクラス -

@property (nonatomic, retain) UITabBarController *tab; 

のUIViewControllerの.mクラス -

viewDidLoadメソッドでこれを追加...

self.tab=[[UITabBarController alloc]init]; 

    // FirstViewController 
    First *fvc=[[First alloc]initWithNibName:nil bundle:nil]; 
    [email protected]"First"; 
    fvc.tabBarItem.image=[UIImage imageNamed:@"i.png"]; 

    //SecondViewController 
    Second *svc=[[Second alloc]initWithNibName:nil bundle:nil]; 
    [email protected]"Second"; 
    svc.tabBarItem.image=[UIImage imageNamed:@"im.png"]; 

    //ThirdViewController 
    Third *tvc=[[Third alloc]initWithNibName:nil bundle:nil]; 
    [email protected]"Third"; 
    tvc.tabBarItem.image=[UIImage imageNamed:@"img.png"]; 

    self.tab.viewControllers=[NSArray arrayWithObjects:fvc, svc, tvc, nil]; 

    [self.view addSubview:self.tab.view]; 

ここで第1、第2および第3は異なる3つのUIViewControllerです。そして、あなたはタブ上でアクションを与える必要はありません。

これは動作します...

+0

ありがとう、私はあなたのコードを試して、それは動作しますが、tabbaritemはbottonの位置にありません。どうしてか分かりません? – user2656381

+0

この写真を見てください:http://img200.imageshack.us/img200/940/ksv.png – user2656381

+0

ok ..通常の画面320 * 480のプロジェクトを作成していますか?320 * 568画面。 –

1

あなたがスターターされている場合は、ベストプラクティスがにありますGoogleで最新のAPIサンプルを検索し、コードを理解して自分の世界を作りましょう。

1)関連するサンプルコードは、apple hereから入手できます。

2)TweetieBar --HereあなたはあなたのUIViewControllerクラスでUITabBarControllerを使用したい場合は、コードの下に、これを使用するカスタムTabBarController(TweetieTabBar)

関連する問題