我是iPhone开发人员的新手,
我的应用程序中有4
页面,我的应用程序为viewBasedApplication
。
我将第一页(LicAppViewController
)设为RootViewController
,这是我的代码。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[LicAppViewController alloc] initWithNibName:@"LicAppViewController" bundle:nil] autorelease];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
按钮点击我导航到第2页(PlanPage
)
-(void)btnClicked{
PlanPage *viewController = [[PlanPage alloc]initWithNibName:@"PlanPage" bundle:nil];
[UIView beginAnimations:@"Flip" context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:viewController animated:YES];
[UIView commitAnimations];
[viewController release];
}
到现在它工作正常,但是当我在第二页中选择一行时会崩溃我的应用程序,我想导航到第3页(DetailPlanPage
),这是我的代码
DetailPlanPage *nextController = [[DetailPlanPage alloc] initWithNibName:@"DetailPlanPage" bundle:nil];
[self.navigationController presentModalViewController:nextController animated:TRUE];
但是当我写作时,这一行:
[self.navigationController pushViewController:nextController animated:YES];
而不是:
[self.navigationController presentModalViewController:nextController animated:TRUE];
它工作正常。 (我不确定但我的应用程序崩溃可能是因为基于viewBased的应用程序)
提前致谢!
答案 0 :(得分:1)
尝试
[self presentModalViewController:nextController animated:YES];
您还希望将nextController的委托设置为self,并添加委托函数以关闭Modal View Controller。
答案 1 :(得分:1)
首先设置rootview控制器
删除该代码
[self.window addSubview:navigationController.view];
并包含
self.window.rootViewController = navigationController;
在现在的模态视图控制器中你可以这样尝试
yourview *detailViewController = [[yourview alloc] initWithNibName:@"yourview" bundle:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismiss)];
detailViewController.navigationItem.leftBarButtonItem = doneButton;
UINavigationController *nav;
nav=[[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
[self presentModalViewController:nav animated:YES];
[detailViewController release];
[doneButton release];
-(void) dismiss
{
[self dismissModalViewControllerAnimated:YES];
}
答案 2 :(得分:0)
最重要的区别在于语义。模态视图控制器通常表示用户必须提供某些信息或执行某些操作。这个链接更深入地解释了它:
当您呈现模态视图控制器时,系统会在执行演示的视图控制器和显示的视图控制器之间创建父子关系。具体来说,执行演示的视图控制器更新其modalViewController属性以指向其呈现的(子)视图控制器。类似地,呈现的视图控制器更新其parentViewController属性以指向呈现它的视图控制器。还有另一个link。