2012-09-06 104 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; 
}