これを行うだけで、他に何も必要ありません。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//replace 'CustomCell' with your custom cell class name
CustomCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.checkBoxImageView.image = [UIImage imageNamed:@"uncheckedimage"];
}
編集:
ただし、テーブルビューがリロードされると、セルが選択されていません。そのために、カスタム セル クラス ヘッダー ファイルで BOOL プロパティを作成します。
@property (retain) BOOL isSelected;
didSelectRowAtIndexPath を次のように変更します。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//replace 'CustomCell' with your custom cell class name
CustomCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.checkBoxImageView.isSelected = YES;
[tableView reloadData];
}
すでにチェックされている行の選択を解除する場合:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
//replace 'CustomCell' with your custom cell class name
CustomCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.checkBoxImageView.isSelected = NO;
[tableView reloadData];
}
そしてあなたの cellForRowAtIndexPath メソッドで:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/*
initialize and set cell properties like you are already doing
*/
if(cell.isSelected) {
cell.checkBoxImageView.image = [UIImage imageNamed:@"uncheckedimage"];
}
else {
cell.checkBoxImageView.image = [UIImage imageNamed:@"checkedimage"];
}
}