【发布时间】:2011-05-22 06:51:09
【问题描述】:
我使用 UIViewController XIB 在 IB 中创建我的 UITableViewCell 然后我用这样的代码实现它:
if(cell == nil)
{
UIViewController *viewController = [[UIViewController alloc] initWithNibName:@"TotalViewCell" bundle:nil];
cell = (TotalViewCell *)viewController.view;
//[viewController release];
}
[[cell totalButton] setTitle:@"$100,000" forState:UIControlStateNormal];
// Action when totalButton is tapped
[[cell totalButton] addTarget:self action:@selector(showTotalDetail:) forControlEvents:UIControlEventTouchUpInside];
return cell;
通常,我会释放 viewController,但我会在该单元格内放置一个 UIButton,当用户点击该按钮时,会调用 showTotalDetail。这是showTotalDetail的代码:
-(void)showTotalDetail:(id)sender
{
// Move the totalTableView up!
CGRect totalDetailTableViewFrame = CGRectMake(20, 200, 280, 200);
[totalTableView setFrame:totalDetailTableViewFrame];
// Reload the new totalTableView
[self viewWillAppear:YES];
}
该函数基本上是调整 tableView 的大小并将其移动到屏幕上的不同位置。所以,如果我释放 viewController,我会得到 EXC_BAD_ACCESS 错误。如果我不释放它会起作用,但我担心我会出现内存泄漏。
有什么建议吗?
谢谢。
【问题讨论】:
标签: iphone objective-c uitableview memory-leaks uiviewcontroller