我正在編寫一個iPhone應用程序,當用戶點擊UITableView中的一個元素時,該應用程序試圖創建第二個視圖。代碼看起來像如何調試內存分配問題?
ReplyToViewController *reply = [[ReplyToViewController alloc] initWithNibName:@"ReplyTo" bundle:nil];
reply.delegate = self;
Message *message = [resultData objectAtIndex:indexPath.row];
int dbid = [message.bizid intValue];
NSLog(@"dbid=%d",dbid);
reply.currentMessage = message;
reply.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:reply animated:YES];
答覆對象得到正確創建和視圖是正確的。上面代碼段的最後一行調用一些框架代碼,最終調用ReplyToViewController的viewDidLoad方法。上面代碼中回覆對象的地址和viewDidLoad中對象的地址不一樣。
任何想法,這個新的對象來自哪裏?我該如何調試?我還在ReplyToViewController中添加了init方法,希望它能夠被調用,並且我可以找到誰在創建這個新對象。但是這種方法並沒有停止。
任何幫助將不勝感激。
- (id) init
{
/* first initialize the base class */
self = [super init];
return self;
}
// Following gets called from the 1st code segment.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(currentMessage.text]; // THIS returns nil and the program fails later in the code.
}