Это должно быть возможно, используя что-то вроде следующего:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
if (lastClickedCell != nil) {
// need to remove button from contentView;
NSArray *subviews = lastClickedCell.contentView.subviews;
for (UIButton *button in subviews) {
[button removeFromSuperview];
}
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// this gives you a reference to the cell you wish to change;
UIButton *cellButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // you can change the type to whatever you want
[cellButton setFrame:CGRectMake(x, y, w, h)]; // you will need to set the x,y,w,h values to what you want
// if you want the button to do something, you will need the next line;
[cellButton addTarget:self action:@selector(someMethod) forControlEvents:UIControlEventTouchUpInside];
// now you will need to place the button in your cell;
[cell.contentView addSubview:cellButton];
[tableView reloadData]; // this updates the table view so it shows the button;
lastClickedCell = cell; // keeps track of the cell to remove the button later;
}
РЕДАКТИРОВАТЬ: вам, конечно, нужно будет удалить кнопку из contentView, когда вы выбираете новую ячейку, поэтому вам понадобится немного логики для этого. Создание подклассов может быть более простым решением, но этот путь вам нужно выбрать, если вы не хотите создавать подклассы. Например, вы хотите объявить следующее в своем заголовке.
UITableViewCell *lastClickedCell;
Тогда вы захотите включить это в вышеприведенное (которое я изменю, чтобы вставить его);