【问题标题】:Can't navigate to nib iphone sdk无法导航到 nib iphone sdk
【发布时间】:2013-09-18 07:56:16
【问题描述】:

这是我导航到另一个笔尖的代码,

  MaintenanceViewController *maintenance = [[MaintenanceViewController alloc] initWithNibName:@"MaintenanceViewController" bundle:nil];
  CGRect theFrame = maintenance.view.frame;
  theFrame.origin = CGPointMake(self.view.frame.size.width, 0);
  maintenance.view.frame = theFrame;
  theFrame.origin = CGPointMake(0,0);
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:0.6f];
  maintenance.view.frame = theFrame;
  [UIView commitAnimations];
  [self.view addSubview:maintenance.view];

请注意,我没有使用导航控制器,我也不想使用,因为我的应用不是基于导航的。

当在第二行调用此方法时,即获取 frame(theframe) 时,应用程序因错误 Exec_bad_access code=2 address = 0xbf7ffffc 而崩溃。

所以 nib 无法加载。

【问题讨论】:

    标签: ios iphone exc-bad-access nib


    【解决方案1】:

    检查此示例SlideMenu

    这可能有助于解决您的问题

    【讨论】:

      【解决方案2】:

      第一件事;您的应用程序崩溃了,因为您正在调用 nill 变量:维护。您需要确保 nib 文件的加载正确进行。

      这没有发生的原因有很多;检查:

      1. 您为 xib 使用了正确的名称,并且该文件存在。
      2. 您已正确定义 xib 文件的“文件所有者”:您的视图控制器。

      第二件事;我认为你想要的是模态地呈现你的第二个视图控制器,这可以通过使用 presentViewController:animated:completion: 方法调用呈现视图控制器来完成。

      【讨论】:

      • 虽然我遇到了问题,但我已正确连接。请用代码解释你想说什么。谢谢
      • @ParasGorasiya 您是否调试并检查维护的值是否为非空?
      • Wezly 的源代码是正确的......但在此之前再次确保维护不是零
      • 我已经使用 if(maintenance == NULL) 进行了检查,但遗憾的是它不是 null
      【解决方案3】:

      要导航到另一个 viewController,您应该使用 presentViewController 方法,如下所示:

      MaintenanceViewController *maintenance = [[MaintenanceViewController alloc] initWithNibName:@"MaintenanceViewController" bundle:nil];
      [maintenance setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
      [self presentViewController:maintenance
                         animated:YES
                       completion:^(void){
                       }
       ];
      

      另外,根据您设置 MaintenanceViewController 的方式,您可能不需要使用 initWithNibName

      MaintenanceViewController *maintenance = [[MaintenanceViewController alloc] init];
      

      【讨论】:

      • 谢谢,但您的解决方案无法帮助我,问题仍然存在。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-11
      • 2012-06-01
      • 1970-01-01
      相关资源
      最近更新 更多