0

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"];

}
4

1 に答える 1

0

If you wont to change something in table view with you function you dont have to make new cell, just modify actual cell. Just make condition in your cellForRowAtIndexPath delegate:

if(indexPath == indexToModify) {
    cell.imageView.image=[UIImage imageNamed:@"checkbox-checked.png"];
} else {
    cell.imageView.image=[UIImage imageNamed:@"checkbox.png"];
}

and in your - (void)OnAction method use in the end:

[self.tableView reloadData];
于 2012-11-01T13:27:16.493 に答える