我與我創建(MyViewController),有一個名爲「按鈕」的UIButton一個視圖控制器工作,這是我一直在試圖獲取代碼它的工作:爲什麼在我調用init方法的超級視圖的時候,這個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;
}
有人能告訴我爲什麼會這樣呢?有沒有辦法解決這個問題,因爲我認爲不這樣做..