0

私のコードでは、テーブル ビューで 1 つのセルを選択すると、別のセルも選択されます。誰でもこれを手伝ってもらえますか。

これは私のコードです:

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

    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Display recipe in the table cell
    Player *player = [players objectAtIndex:indexPath.row];

    UILabel *playerIdLabel = (UILabel *)[cell viewWithTag:104];
    playerIdLabel.text = player.pid;

    UIImageView *playerImageView = (UIImageView *)[cell viewWithTag:100];
    playerImageView.image = [UIImage imageNamed:player.imageFile];

    UILabel *playerNameLabel = (UILabel *)[cell viewWithTag:101];
    playerNameLabel.text = player.name;

    UILabel *playerDetailLabel = (UILabel *)[cell viewWithTag:102];
    playerDetailLabel.text = player.detail;

    UIButton *playerAddButton = (UIButton *)[cell viewWithTag:103];

    // Assign our own background image for the cell
    UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];

    UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
    cellBackgroundView.image = background;
    cell.backgroundView = cellBackgroundView;

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UILabel *playerNameLabel = (UILabel *)[cell viewWithTag:101];
        NSString *playerName = playerNameLabel.text;

        UILabel *playerIdLabel = (UILabel *)[cell viewWithTag:104];
        [playerIdLabel setHidden:NO];
}
4

2 に答える 2

0

再利用識別子に nil を設定するには、これを試してください。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
于 2013-09-19T09:43:56.623 に答える
0

IB から Cell のサイズを縮小し、デリゲート メソッドを使用して高さを設定するのを忘れた可能性があると思います。これを試して

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return 30.0;
}
于 2013-09-19T09:45:33.363 に答える