当视图控制器从导航控制器弹出时应用程序崩溃

发布于 2024-12-09 23:39:23 字数 402 浏览 0 评论 0原文

我正在导航控制器上推送一个对象,但是当我从该视图控制器返回控制时,它会使应用程序崩溃。

[self.navigationController pushViewController:chequeDetails animated:YES];
        [chequeDetails release];

但是当我用应用程序编写相同的代码时

[self.navigationController pushViewController:chequeDetails animated:YES];
 chequeDetails=nil;
[chequeDetails release];

不会崩溃,但会观察到轻微的滞后......当我从检查详细信息控制器弹出时?

I am pushing an object on navigation controller but when I return the control from the that view controller it crashes the app.

[self.navigationController pushViewController:chequeDetails animated:YES];
        [chequeDetails release];

but when I write the same code with

[self.navigationController pushViewController:chequeDetails animated:YES];
 chequeDetails=nil;
[chequeDetails release];

The app does not crash but a slight lag is observed... when i pop back from the check details controller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你好,陌生人 2024-12-16 23:39:23

如果您的秒示例代码,您不会释放 chequeDetails 因为在 nil 对象上调用 release 不会执行任何操作:

[self.navigationController pushViewController:chequeDetails animated:YES];
 chequeDetails=nil;
// calling the release on nill will do nothing
[chequeDetails release];

通常您可以这样做:

[self.navigationController pushViewController:chequeDetails animated:YES];
[chequeDetails release], chequeDetails = nil;

但只释放 < code>chequeDetails 如果您进行了分配,则 init 如下:

ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil];

所以完整的代码应该类似于:

ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil];
[self.navigationController pushViewController:chequeDetails animated:YES];
[chequeDetails release], chequeDetails = nil;

If your seconds exaple code, you are not release the chequeDetails since calling release on a nil object does not nothing:

[self.navigationController pushViewController:chequeDetails animated:YES];
 chequeDetails=nil;
// calling the release on nill will do nothing
[chequeDetails release];

Normally you can do it this ways:

[self.navigationController pushViewController:chequeDetails animated:YES];
[chequeDetails release], chequeDetails = nil;

But only release the chequeDetails if you did a alloc, init like:

ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil];

So the full code should be something like:

ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil];
[self.navigationController pushViewController:chequeDetails animated:YES];
[chequeDetails release], chequeDetails = nil;
野侃 2024-12-16 23:39:23

我不知道 Exat...但我认为您需要创建委托的对象,并且需要编写 appDelegate.navigationController 而不是 self.navigationController...

注意:appDelegate 是 Delegate 的对象。

I dont Know Exat... but i think you need to create a object of your delegate and you need to write appDelegate.navigationController rather then self.navigationController...

Note: appDelegate is a object of Delegate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文