我正在编写一个 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.
}