0

私のコードでは、UITableViewのセルを選択したいと思います。ここで選択を行いますが、選択するたびに一瞬だけ選択されてしまい、選択が失われます。

私は何を間違えましたか?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableIdentifier"];

    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SimpleTableIdentifier"];
    }

    cell.textLabel.text = [[self tableViewArray] objectAtIndex:indexPath.row];

    if(indexPath.row == self.selectedTopicIndex)
    {
        NSLog(@"DIE DIE DIE DIE DIE!!!");
        [cell setSelected:YES];
        [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
        [cell setSelected:YES];
    }

    return cell;
}
4

1 に答える 1

1

選択ロジックを-tableView:willDisplayCell:forRowAtIndexPath:メソッド内に移動するだけです。このようなもの:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == self.selectedTopicIndex)
    {
        NSLog(@"DIE DIE DIE DIE DIE!!!");
        [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
        [cell setSelected:YES];
    }
}
于 2012-07-05T09:43:47.023 に答える