Небольшой фон, табличное представление заполняется fetchedResultsController, который заполняет табличное представление строками. Теперь я пытаюсь добавить кнопку рядом с каждой строкой в каждой ячейке таблицы. До сих пор я пытался создать кнопку в своем методе configureCell: atIndexPath, а затем добавить эту кнопку в качестве подпредставления в представление содержимого ячейки таблицы, но по какой-то причине кнопки не отображаются. Ниже приведен соответствующий код. Если кто-то хочет опубликовать больше кода, просто спросите, и я выставлю все, что вы захотите. Любая помощь с благодарностью.
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
// get object that has the string that will be put in the table cell
Task *task = [fetchedResultsController objectAtIndexPath:indexPath];
//make button
UIButton *button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[button setTitle:@"Check" forState:UIControlStateNormal];
[button setTitle:@"Checked" forState:UIControlStateHighlighted];
//set the table cell text equal to the object's property
cell.textLabel.text = [task taskName];
//addbutton as a subview
[cell.contentView addSubview:button];
}
- (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];
}
// Configure the cell.
[self configureCell:cell atIndexPath:indexPath];
return cell;
}