画像を変更したい TableView が設定されています。cellForRowAtIndexPath 内にいるときは、次を使用して変更できます。
cell.imageView.image = [UIImage imageNamed:@"image.png"];
しかし、ボイド内で同じことを行う方法がわかりません。試しました:
[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]].imageView.image = [UIImage imageNamed:@"image.png"];
でも全然イメージ変わりません。
ありがとう、/DSDeniso
編集:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
_row = indexPath.row;
[self changeImage];
}
- (void)changeImage{
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:_row inSection:0]];
if(cell)
{
cell.imageView.image = [UIImage imageNamed:@"image.png"];
} else {
NSLog( @"why is cell null? Did I set row properly?");
}
}