Objective c 为什么当我在超级视图中调用init方法时,这个UIButton没有被初始化?

Objective c 为什么当我在超级视图中调用init方法时,这个UIButton没有被初始化?,objective-c,ios4,uiviewcontroller,uibutton,Objective C,Ios4,Uiviewcontroller,Uibutton,我正在使用我创建的视图控制器(MyViewController),它有一个名为“button”的UIButton,这是我一直试图让它工作的代码: - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { MyViewController *myViewController=[[[MyViewController alloc] init] autorelease]; [myV

我正在使用我创建的视图控制器(MyViewController),它有一个名为“button”的UIButton,这是我一直试图让它工作的代码:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
MyViewController *myViewController=[[[MyViewController alloc] init] autorelease];
[myViewController.button addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
return footerController.view;
}
我不确定它出了什么问题,但如果我这样做,显然我可以修复它:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
MyViewController *myViewController=[[[MyViewController alloc] init] autorelease];
[myViewController.view addSubview:nil];
[myViewController.button addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
return footerController.view;
}

有人能告诉我为什么会这样吗?有没有办法解决这个问题,因为我不认为这样做是可以的。

nib在需要保存内存之前不会加载,正如正在访问的
视图
属性所示。如果可能,最好在MyViewController的
viewDidLoad
方法中进行这种初始化。

Anomie所说的是正确的。。我找到了绕过它的方法。。我不能直接使用
myViewController.button
访问按钮,而是必须使用以下方法:
[myViewController.view viewWithTag:buttonTag]
。这样我就可以确保按钮已经初始化