我以编程方式向我的tableview添加了一个按钮,但只有当我选择tableview cell时它才可见。我可以让它出现而不管tableview的选择是什么,我想做tableviewcell none.how的选择样式继续。 这是我使用的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
ContactDetails *cont= [self.contactarray objectAtIndex:indexPath.row];
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
for(ContactDetails *mycontact in delegate.contactsArray )
{
if([mycontact.contactID isEqualToString:cont.contactID])
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 0, 100, 40);
[button setTitle:@"add contact" forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(deconnect) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];
[cell.contentView bringSubviewToFront:button];
}
}
cell.textLabel.text=cont.name;
return cell;
}
答案 0 :(得分:3)
[cell addSubview:button];
抱歉让对不起