0

我是 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; 
}

在按钮上单击我导航到第二页(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];

}

到目前为止它工作正常,但是当我在第二页中选择一行时,它会使我的应用程序崩溃,我想导航到第三页(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];

它工作正常。(我不确定,但我的应用程序崩溃可能是因为基于视图的应用程序

提前致谢 !

4

3 回答 3

1

尝试

[self presentModalViewController:nextController animated:YES];

您还希望将 nextController 的委托设置为 self 并添加一个委托函数来关闭模态视图控制器。

于 2012-06-20T06:24:44.000 回答
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];
  }
于 2012-06-20T07:21:55.963 回答
0

最重要的区别在于语义。模态视图控制器通常指示用户必须提供一些信息或做某事。此链接更深入地解释它:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

当您呈现一个模态视图控制器时,系统会在执行呈现的视图控制器和被呈现的视图控制器之间创建父子关系。具体来说,执行呈现的视图控制器更新其 modalViewController 属性以指向其呈现的(子)视图控制器。类似地,呈现的视图控制器更新其 parentViewController 属性以指向呈现它的视图控制器。还有另一个链接

于 2012-06-20T06:26:07.823 回答