Ipad 由于AppDelegate方法,切换视图时出错

Ipad 由于AppDelegate方法,切换视图时出错,ipad,ios5,uiview,Ipad,Ios5,Uiview,这就是我在应用程序中所做的: 在我的appDelegate.m文件中 //Four Views @synthesize fvc; @synthesize svc; @synthesize tvc; @synthesize pvc; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { NSString *name1,*n

这就是我在应用程序中所做的:

在我的appDelegate.m文件中

//Four Views
@synthesize fvc;
@synthesize svc;
@synthesize tvc;
@synthesize pvc;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
 {
 NSString *name1,*name2,*name3;
 name1 = NSLocalizedString(@"home", nil);
 name2 = NSLocalizedString(@"quote", nil);
name3 = NSLocalizedString(@"ship", nil);
UITabBarController *tabBar = [[UITabBarController alloc] init];

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 

 //[application setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
tvc = [storyboard instantiateViewControllerWithIdentifier:@"thirdview"];
fvc = [storyboard instantiateViewControllerWithIdentifier:@"firstview"];
svc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

 pvc =[storyboard instantiateViewControllerWithIdentifier:@"PayViewController"];

fvc.tabBarItem.title = name1;
 fvc.tabBarItem.image = [UIImage imageNamed:@"home.png"];
 fvc.tabBarItem.titlePositionAdjustment = UIOffsetMake(2.0, 0);

 tvc.tabBarItem.title = name2;
 tvc.tabBarItem.image = [UIImage imageNamed:@"ping.png"];
 tvc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, 2.0);

 svc.tabBarItem.title = name3;
 svc.tabBarItem.image = [UIImage imageNamed:@"zoom.png"];    
 svc.tabBarItem.titlePositionAdjustment = UIOffsetMake(-5.0, 0);

 NSLog(@"appdelegate %@ and %@",svc,svc.title);

 tabBar.viewControllers = [NSArray arrayWithObjects:fvc,svc,tvc,nil];

 // the below line does not allow [self.navigationController pushViewController:svNew  animated:YES]; to function

 self.window.rootViewController = tabBar;
 // Override point for customization after application launch.
 return YES;
在我的fvc视图中,我正在okPressed方法中执行更改视图操作:

 - (IBAction)okPressed:(id)sender {
 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 

 SecondViewController *svNew = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

 [self.navigationController pushViewController:svNew animated:YES];
 }

当我在appdelegate方法中注释代码时,通过okPressed方法在视图之间的切换将成功执行。但是,当我取消对appDelegate方法的注释时,它不会执行切换。我发现,appdelegate方法“self.window.rootViewController=tabBar;”中的代码是罪魁祸首。有人能给我一些指导吗。

我想你应该把你的UITabBarController嵌入到导航控制器中,让它工作:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tabBar];
然后

self.window.rootViewController = navController;

否则你不能推任何东西,因为你可能没有UINavigationController来推东西

我认为您应该在导航控制器中嵌入UITabBarController,使其工作:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tabBar];
然后

self.window.rootViewController = navController;
否则你不能推任何东西,因为你可能没有UINavigationController来推东西