簡體   English   中英

Tabbar控制器加載空XIB

[英]Tabbar controller load empty xib

我正在嘗試構建一個在開始時具有3個按鈕的主視圖的應用程序,然后當用戶按下這些按鈕中的任何一個按鈕時,選項卡欄視圖將與選定的選項卡欄項一起出現。

我的問題是在這里,當選項卡欄視圖應出現時...它似乎是空的!

- (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];
    }

在此處輸入圖片說明

您必須設置TabbarViewController的viewControllers屬性(當然,如果它是UITabBarController的超類)。 在TabbarViewController的init方法中創建3個viewControllers,將它們添加到數組並將其設置為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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM