【问题标题】:Unable to navigate to next page iPhone无法导航到下一页 iPhone
【发布时间】:2012-06-20 06:10:27
【问题描述】:

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

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

提前致谢!

【问题讨论】:

    标签: iphone ipad uitableview uinavigationcontroller rootview


    【解决方案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];
      }
    

    【讨论】:

    • dude you Rock,我的代码运行良好,我可以在新页面上看到导航栏,但里面没有返回按钮。
    • 工作正常,有没有看起来像后退按钮的样式?给我这个答案,我会接受你的回答
    • 使用后退按钮图像..UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back-button.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss )] 自动释放]; self.navigationItem.leftBarButtonItem = backButton;
    • 是的,这是我的错误。无论如何感谢帮助。
    【解决方案2】:

    试试

    [self presentModalViewController:nextController animated:YES];
    

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

    【讨论】:

    • @Krunal:应该可以使用模态视图控制器。我有一个更新版本的 Xcode,所以我尝试创建一个简单的单视图应用程序,我可以展示一个模态视图控制器。你有任何与崩溃相关的输出吗?
    • 我遵循了 Rams 的回答,它运行良好 感谢您的帮助。
    【解决方案3】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-31
      • 2012-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多