2012-09-06 52 views
1

我試圖建立一個應用程序,其中有3個按鈕的開始主視圖,然後當用戶按下這些按鈕的任何按鈕時,選項卡欄視圖將出現選定的選項卡欄項目。Tabbar控制器加載空的xib

我的問題是在這裏,當標籤欄視圖應該出現......它看起來是空的!在主功能表視圖

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 

    MainMenuViewController *mainMenuViewController = [[[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil] autorelease]; 
    self.navigationController = [[[UINavigationController alloc] initWithRootViewController:mainMenuViewController] autorelease]; 
    self.window.rootViewController = self.navigationController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

//按鈕操作 -

(IBAction)button1Action:(id)sender { 
     TabbarViewController *tempView = [[TabbarViewController alloc] initWithNibName:@"TabbarViewController" bundle:nil]; 
     [self.navigationController pushViewController:tempView animated:YES]; 
     [tempView release]; 
    } 

enter image description here

回答

0

你必須設置你的TabbarViewController的viewControllers屬性(當然如果是的UITabBarController的超類)。在TabbarViewController的init方法中創建3個viewController,將它們添加到數組並將其設置爲像這樣的viewControllers屬性:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     NSLog(@"%@",[[self class] superclass]); 

     UIViewController *yourFirstViewController = [[UIViewController alloc] init]; 
     UIViewController *yourSecondViewController = [[UIViewController alloc] init]; 
     UIViewController *yourThirdViewController = [[UIViewController alloc] init]; 

     yourFirstViewController.title = @"First"; 
     yourSecondViewController.title = @"Second"; 
     yourThirdViewController.title = @"Third"; 

     NSArray *threeViewControllers = [[NSArray alloc]initWithObjects:yourFirstViewController, yourSecondViewController, yourThirdViewController, nil]; 

     self.viewControllers = threeViewControllers; 

     // Custom initialization 
    } 
    return self; 
}