我在TableView中有一個自定義單元格,單元格中有一個按鈕。當我選擇單元格時,背景變成藍色,按鈕消失。有什麼辦法可以防止這種情況發生?如何防止按鈕在選擇TableView單元格時消失?
這樣的的cellForRowAtIndexPath -
對選定的表格單元- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[MyTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
Search *current = [self.retrievedTweets objectAtIndex:indexPath.row];
cell.textLabel.text = current.text;
cell.textLabel.font = [UIFont systemFontOfSize:15.0];
cell.textLabel.numberOfLines = 2;
cell.detailTextLabel.text = current.name;
cell.imageView.image = current.userImage;
btnUncheck =[[UIButton alloc] initWithFrame:CGRectMake(400, 35, 20, 20)];
btnUncheck.backgroundColor = [UIColor redColor];
btnUncheck.layer.cornerRadius = 10;
btnUncheck.hidden =NO;
btnUncheck.tag=indexPath.row;
//[btnUncheck addTarget:self action:@selector(didSelectRowAtIndexPath:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:btnUncheck];
return cell;
}
你是如何添加按鈕的? – jrturton
'btnUncheck = [[UIButton alloc] initWithFrame:CGRectMake(400,35,20,20)]; btnUncheck.backgroundColor = [UIColor redColor]; btnUncheck.layer.cornerRadius = 10; [cell.contentView addSubview:btnUncheck];' –