TableView
iOS でa をサポートするテキスト配列があります。: メソッドではcellForRowAtIndexPath
、バッキング配列からのテキストが取り込まれた UITableViewCell* を返します。indexPath は、バッキング配列へのインデックスとして使用されます。
の最後のセルに「完了」ボタンを追加したいと思いますTableView
。私の StoryBoard では、2 番目の (プロトタイプ)TableView Cell
を作成し、「ButtonCell」という識別子を付けました。numberOfRowsInSection: がバッキング配列のカウントを返すことができ、すべてが機能するように、バッキング配列の最後に追加の要素も追加しました。
最後の配列要素のテキストを @"donebutton" のようなものに設定すると、cellForRowAtIndexPath: でそれを確認できると思いました。それが真であれば、配列の最後にいることがわかり、通常の「Cell」ではなく「ButtonCell」セルを返すことになります。問題は、それがうまく機能していないということです。これを達成するための最良の方法は何ですか? コードスニップは以下です。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
static NSString *ButtonCellIdentifier = @"ButtonCell";
UITableViewCell *bcell = [tableView dequeueReusableCellWithIdentifier:ButtonCellIdentifier forIndexPath:indexPath];
NSString *rowtext = [_mArCellData objectAtIndex:indexPath.row];
// return button cell if last item in list
if ([rowtext isEqualToString:[NSString stringWithFormat:@"%d", SUBMIT_BUTTON]])
{
NSLog(@"hit last row, so using button row");
return bcell;
}
cell.textLabel.text = rowtext;
return cell;
}