2

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

  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

所以笔尖无法加载。

4

3 回答 3

3

检查此示例SlideMenu

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

于 2013-09-18T09:37:46.953 回答
2

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

没有发生这种情况有不同的原因;查看:

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

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

于 2013-09-18T08:06:16.933 回答
2

要导航到另一个 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];
于 2013-09-18T08:09:14.500 回答