添加到UITableViewCell的UIButton将无法显示

use*_*859 0 iphone uibutton uitableview

在阅读了这里和其他地方的所有示例之后,我编写了以下代码来向UITableViewCell添加一个按钮,但我无法在单元格中显示它.我究竟做错了什么?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
   }

UIButton *cellButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cellButton setFrame:CGRectMake(0.0f, 5.0f, tableView.frame.size.width-2, 44.0f)];
[cellButton setTitle:[aList objectAtIndex:indexPath.row] forState:UIControlStateNormal];
[cell.contentView addSubview:cellButton];
[cellButton release];
return cell;
}   
Run Code Online (Sandbox Code Playgroud)

谢谢,约翰

fbr*_*eto 6

无需拨打release您创建的按钮buttonWithType; 通过调用release你会导致保留计数下降,并且在某些时候按钮将被破坏之前你想要它.