私はかなり珍しい状況にあり、メモリ管理を正しく理解していません。
メッセージを表示するためのUITableViewControllerがあり、UINavigationControllerを作成し、そのビューを表示するために現在のビューのサブビューとして追加します。私が抱えている問題は、UINavigationControllerをリリースしないために、Xcodeがメモリリークの可能性があることを報告していることです(同意します)が、以下のコードのようにリリースすると、クリックして戻ったときにアプリがクラッシュしますテーブルビュー。
UITableViewControllerの保持プロパティを使用して、現在のUINavigationControllerを追跡し、保持カウントを管理しましたが、明らかにここに何かが欠けています。
注:クラッシュは、メッセージ-[UILayoutContainerView removeFromSuperview:]:認識されないセレクターがインスタンス0x5537db0に送信された状態で[戻る]ボタンをクリックすると発生します。
また、コードの[nc release]行を削除すると、正常に機能することにも注意してください。
これが私のコードです:
@property(nonatomic, retain) UINavigationController *currentNavigationController;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UINavigationController *nc = [[UINavigationController alloc] init];
CGRect ncFrame = CGRectMake(0.0, 0.0, [[self view] frame].size.width, [[self view] frame].size.height);
[[nc view] setFrame:ncFrame];
// I created a CurrentNavigationController property to
// manage the retain counts for me
[self setCurrentNavigationController:nc];
[[self view] addSubview:[nc view]];
[nc pushViewController:messageDetailViewController animated:YES];
UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonSystemItemRewind target:[nc view] action:@selector(removeFromSuperview:)];
nc.navigationBar.topItem.leftBarButtonItem = bbi;
[bbi release];
[nc release];
}