How to create a tab bar controller with presents a nil modal view
i am creating an application which make uses of tabbar.i have created a function named setuptabbar which calls all the classes that use tab bar . this my code.
-(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:@"Scr开发者_开发知识库een" bundle:nil];
[window addSubview:mTabController.view];
[self.window makeKeyAndVisible];
//[screen release];
return YES;
}
But when i run the project it gives me an error that 'Application tried to present a nil modal view controller.What is the problem.
In you following line:
[mTabController presentModalViewController:mViewController animated:YES];
You are presenting mViewController from mTabController. What is mViewController ? It's maybe because mViewController is never allocated. If you remove this line I think your code is working.
精彩评论