これは私が私のアプリケーションでやっていることです:
私の 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;」です。が犯人です。誰でもこれについて私を案内できますか。