didSelectRowAtIndexPathを使用しているtableViewでviewControllerをプッシュすると、iOS 4.3でクラッシュする原因がわかりますが、iOS 5.0以降では問題なく動作します。オブジェクトdeallocがiOS 4.3でクラッシュするだけです。
それは私が呼んで右のときにクラッシュ:
self.customViewController = [[[CustomViewController alloc] initWithNibName:@"CustomViewController"bundle:nil] autorelease];
いつでもcustomViewControllerが押された最初の時間後。
@property (nonatomic, retain) CustomViewController *customViewController;
-(void) dealloc // Dealloc of tableView.
{
[customViewController release];
customViewController = nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.customViewController = [[[CustomViewController alloc] initWithNibName:@"CustomViewController"bundle:nil] autorelease]; // Release old, allocate new, set it.
[[self navigationController] pushViewController:customViewController animated:YES];
[customViewController release]; // Balance out pushViewController's retain.
}
ありがとう:
は、ここに私の関連するコードです。
真剣に待ちますか? viewControllerを保持していると本当に思っていましたが、ビューを保持していると思いますか? –
@JoeRaytheinビューコントローラは保持されますが、リリースされます。それはそれの所有権が必要です。autoreleaseを呼び出すと、すでに所有権を放棄しています。 –
しかし、私は 'release'は、コントローラがプッシュされているときにアプリケーションをクラッシュさせてはならないと思っています。' didSelectRowAtIndexPath'ではなく 'dealloc'メソッドでクラッシュさせるべきです。 – Ecarrion