2014-05-14 95 views
0

UITabbarController.xibUILabel作爲SubViewUILabel添加到xib的UITabbarController視圖被UITabbarController隱藏子視圖控制器

當我運行應用程序UILabel不可見,因爲子視圖控制器隱藏UILabel

我希望UILabel在所有ChildView控制器中都可見。

當我調試viewDidLoadviewWillAppear該標籤看起來nil對象雖然我已經在TabBarController.h文件IBOutlet連接的代碼。

我有這樣的代碼在.h文件中這一

@interface TestTabBarController : UITabBarController <UITabBarControllerDelegate> 

@end 
and in .m file 

@interface TestTabBarController() 
@property (weak, nonatomic)IBOutlet UILabel *historylabel; 
@end 


@implementation TestTabBarController 

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

    } 
    return self; 
} 
-(void)setChildrenViewControllers 
{ 
    // Set the View Controllers. 
    FirstViewController *viewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 

    SecondViewController *viewcontroller2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

    ThirdViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil]; 

    FourthViewController *viewController4 = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil]; 

self.viewControllers = @[viewController,viewcontroller2,viewController3,viewController4]; 


self.delegate = self; 
} 

@end 

我打電話的Tabbarcontroller類如下

TestTabBarController *testtabbar = [[TestTabBarController alloc] initWithNibName:@"TestTabBarController" bundle:nil]; 
[testtabbar setChildrenViewControllers]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:testtabbar]; 
[self.navigationController presentViewController:navController animated:YES completion:nil]; 

回答

0

我有廈門國際銀行的子類的UITabBarController - 這是一個視圖。如果我在xib視圖頂部添加標籤,它將不會顯示,如果因爲viewcontroller是tabbarcontroller.tabbarcontroller的子類只接受tabbar作爲子視圖,它不會接受所以我們必須添加項目到每個子控制器,否則在tabbarcontroller類的viewdidload類創建一個標籤分配和初始化它,並添加它像

[self.view addsubview:label];

如果您在xib視圖上添加標籤,那麼它將不會在子視圖控制器上可見,如果您在viewdidload中強制加載nib,那麼nib將是visiblw,但不是tabbarcontroller和子視圖controllers.Hope這將幫助每個人。

相關問題