如果您有一个带有图像名称的数组,那么最简单的方法是更改数组中选定索引处的名称并重新加载表......像这样:
myImageArray = [[NSMutableArray alloc] init];
[myImageArray addObject:@"name1.jpg"];
[myImageArray addObject:@"name2.jpg"];
// etc..
而在 cellForRowAtIndexPath 方法中:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
[cell.imageView setImage:[UIImage imageNamed:[myImageArray objecAtIndex:indexPath.row]]];
}
在 didSelectRowAtIndexPath 中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[myImageArray setObject:@"newName.jpg" atIndexedSubscript:indexPath.row];
[tableView reloadData];
}