这就是我在应用程序中所做的:
在我的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;”中的代码是罪魁祸首。有人能指导我吗。