2011-03-29 53 views
1

我正在創建一個應用程序,它使tabbar.i創建了一個名爲setuptabbar的函數,它調用了所有使用標籤欄的類。這是我的代碼。如何創建一個標籤欄控制器,提供一個無模式視圖

-(void)setupTabbar{ 
    //this is used to allocate space for tab bar item. 
    TJourneylistController *journeylist =[[TJourneylistController alloc]initWithNibName:nil bundle:nil]; 
    UINavigationController *journeylistnavigation =[[UINavigationController alloc]initWithRootViewController:journeylist]; 
    [journeylist.tabBarItem initWithTitle:@"Journey List" image:[UIImage imageNamed:@""] tag:2]; 
    [journeylist release]; 

    TAppStoreController *appstore =[[TAppStoreController alloc]initWithNibName:nil bundle:nil]; 
    UINavigationController *appstorenavigation =[[UINavigationController alloc]initWithRootViewController:appstore]; 
    [appstore.tabBarItem initWithTitle:@"App Stroe" image:[UIImage imageNamed:@""] tag:1]; 
    [appstore release]; 

    TSettingsController *settings =[[TSettingsController alloc]initWithNibName:nil bundle:nil]; 
    UINavigationController *settingsnavigation =[[UINavigationController alloc]initWithRootViewController:settings]; 
    [settings.tabBarItem initWithTitle:@"Journey List" image:[UIImage imageNamed:@""] tag:3]; 
    [settings release]; 

    TAboutController *about =[[TAboutController alloc]initWithNibName:nil bundle:nil]; 
    UINavigationController *aboutnavigation =[[UINavigationController alloc]initWithRootViewController:about]; 
    [about.tabBarItem initWithTitle:@"Journey List" image:[UIImage imageNamed:@""] tag:4]; 
    [about release]; 

    mTabController.viewControllers = [[NSArray alloc] initWithObjects:appstorenavigation,journeylistnavigation,settingsnavigation,aboutnavigation,nil]; 
    [appstorenavigation release]; 
    [journeylistnavigation release]; 
    [settingsnavigation release]; 
    [aboutnavigation release]; 
} 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // Override point for customization after application launch. 

    mTabController = [[UITabBarController alloc]init]; 
    [self setupTabbar]; 
    if([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]!=nil) 
     mTabController.selectedViewController = [mTabController.viewControllers objectAtIndex:0]; 
    [mTabController presentModalViewController:mViewController animated:YES]; 
    //Screen *screen =[[Screen alloc]initWithNibName:@"Screen" bundle:nil]; 
    [window addSubview:mTabController.view]; 
    [self.window makeKeyAndVisible]; 
    //[screen release]; 

    return YES; 
} 

但是,當我運行該項目它給了我一個錯誤,'應用程序試圖提出一個無模式視圖controller.What是這個問題。

回答

0

在你下面一行:

[mTabController presentModalViewController:mViewController animated:YES]; 

您從mTabController呈現mViewController。什麼是mViewController?這可能是因爲mViewController從未分配過。如果你刪除這一行,我認爲你的代碼正在工作。

+0

謝謝先生,我試過這個我刪除了行,現在我的代碼工作正常 – Rocky 2011-03-29 11:40:55

相關問題