【问题标题】:navigation bar back button , crash the app导航栏后退按钮,应用崩溃
【发布时间】:2012-11-28 11:10:15
【问题描述】:

我有基于导航的应用程序。我在应用程序didFinishLaunchingWithOptions 委托方法中创建了一个UINavigationController,如下所示:

self.initialviewcontroller = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil];
UINavigationController *myNavController = [[UINavigationController alloc] initWithRootViewController:self.initialviewcontroller];

self.window.rootViewController = myNavController;
[self.window makeKeyAndVisible];

InitialViewController 中,我有一个按钮可以导航到SecondViewController。因此,在按钮的操作中,我按下SecondViewController 如下:

if(self.secondView != nil)
  self.secondView = nil;
self.secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:self.secondView animated:YES];

情况:导航工作正常,我可以在InitialViewControllerSecondViewController 之间导航。当我在SecondViewController 并按下设备的主页按钮时,应用程序进入后台,当我重新打开应用程序时,它会从我关闭它的位置打开应用程序(即 SecondViewController)。现在,如果我按下返回按钮转到 InitialViewController,应用程序就会崩溃。

在 ios 模拟器中运行良好,但在设备上发生崩溃。

我不明白我犯了什么错误?

这是我的错误代码

异常类型:EXC_BAD_ACCESS (SIGSEGV) 异常代码:0x654b495d 处的 KERN_INVALID_ADDRESS 崩溃的线程:0

线程 0 名称:调度队列:com.apple.main-thread

【问题讨论】:

  • 将错误文本发送给我们。
  • 另外,当您的 nib 与您的 View Controller 同名时,您可以使用[[SecondViewController alloc] init];,它会默认使用同名的 nib。
  • 我认为问题是当应用程序进入后台时系统正在释放InitialViewController 实例,以确保您可以在deallocInitialViewController 方法中添加NSLog() 调用类
  • UINavigationController 确实保留了它的每个子 UIViewcontroller 对象。但是在每个 initialViewController 状态更改方法中检查 NSLogs 肯定是值得的,比如viewWillAppear
  • UINavigationController 保留在它的子 UIViewcontroller 对象中,我可以从那里推送另一个视图控制器....

标签: ios


【解决方案1】:

你的代码是

if(self.secondView != nil)
  self.secondView = nil;
self.secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:self.secondView animated:YES];

用下面的代替这个。

SecondViewController *secondViewobj = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self.navigationController pushViewController:secondViewobj animated:YES];

【讨论】:

    【解决方案2】:

    我认为您的问题是 uinavigationcontroller 正在被释放。 您应该像第一个一样将您的 secondView 放在 uinavigationcontroller 中,然后重试。

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-07
      • 2015-05-02
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多