2013-08-09 10 views
5

Jak push Viewcontroller z TabbarController? W ViewController'XIB utworzyłem UITabbarController. Następnie popycham ten ViewController, ale nie pojawia się UITabbarController. To jest mój kod: * Viewcontroller.h:Jak dodać UITabbarController do UIViewController w iOs

@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]; 


} 

Dzięki za pomoc

+0

Pytanie, które zostały przedstawione tutaj nie jest zrozumiałe ..Plz Zrób to właściwe? –

+0

dynamicznie zmieniasz swój widok root, możesz to zrobić. Co jest potrzebne, aby popchnąć UITabbarcontoller – Vinodh

Odpowiedz

9

Jeśli chcesz użyć UITabBarController w klasie UIViewController następnie użyć tego kodu poniżej ...

UIViewController .h Class -

@property (nonatomic, retain) UITabBarController *tab; 

UIViewController .m Class -

Dodaj ten w sposób 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]; 

tutaj Pierwszy, drugi i trzeci to trzy różne kontrolery UIViewController. I nie musisz podawać akcji na kartach.

Będzie ona działać ...

+0

Dzięki, próbowałem twój kod, działa, ale tabbaritem nie jest w pozycji BOTTON. Nie wiem dlaczego? – user2656381

+0

Proszę zobaczyć to zdjęcie: http://img200.imageshack.us/img200/940/ksv.png – user2656381

+0

ok .. czy tworzysz projekt dla normalnego ekranu 320 * 480 .... To nie pokaże ci 320 * 568 ekran. Powinieneś ustawić współrzędne ramek zgodnie z twoim rozmiarem ekranu. –

1

Jeśli to rozrusznik, najlepszym rozwiązaniem jest wyszukuj w Google dla najnowszych próbek api, następnie zrozum kod i twórz własny świat.

1) Można znaleźć powiązane kody przykładowe z jabłka here.

2) TweetieBar --Here jest przykładowy kod z niestandardowym TabBarController (TweetieTabBar)

Powiązane problemy