背景はほとんどありませんが、テーブルビューは、テーブルビューを文字列で埋める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;
}