UITableViewのセルにデータと画像があります。特定のセルの画像を変更したいのですが、各セルにコードがあります。
セルのテーブルビューを繰り返す方法が見つかりません。
これが私のテーブルビュー関数のスナップショットです。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellText = nil;
NSArray *keys = [[[self packageItems] allKeys]
sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
cellText = [keys objectAtIndex:[indexPath row]];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
cell.imageView.image=[UIImage imageNamed:@"checkbox.png"];
//cell.imageView.image=[UIImage imageNamed:@"checkbox-checked.png"];
return cell;
}
セル画像をcell.imageView.image=[UIImage imageNamed:@"checkbox-checked.png"]に変更したい別の関数があります。
- (void)OnAction
{
static NSString *CellIdentifier = @"Cell";
NSIndexPath *indexPath = [[NSIndexPath alloc] initWithIndex:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath ];
cell.imageView.image=[UIImage imageNamed:@"checkbox-checked.png"];
}