如何将初始UIViewController添加到现有的COreData应用程序?
问题描述:
我为我的应用程序使用模型“主 - 细节应用程序”,并且想设置不同的初始视图。可能吗?我想用菜单按钮显示UIViewController,其中一个按钮应该加载前一个原始初始视图的导航控制器。如何将初始UIViewController添加到现有的COreData应用程序?
当我将storyBoards UI中的初始视图更改为ViewController并将该按钮链接到NavigationController时,应用程序将压碎。
什么是正确的做法?
谢谢你的时间!
答
包含此代码到AppDelegate中:
- (void)tellDelegateToFlip{
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
masterViewController.managedObjectContext = self.managedObjectContext;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromLeft forView:self.window cache:YES];
[self.navigationController pushViewController:masterViewController animated:YES];
[UIView commitAnimations];
}
而且这种方法将初始视图调用主视图:
-(IBAction)flipToMaster:(id)sender{
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tellDelegateToFlip];
}
就大功告成了!
应用程序崩溃时会出现什么错误?这应该是完全可能的! – deanWombourne 2012-03-26 16:24:01