2013-09-19 3 views
0

В моем коде, когда я выбираю одну ячейку в виде таблицы, она также выбирает другую ячейку. Может кто-нибудь помочь с этим.didSelectRowAtIndexPath выбирает другую ячейку, чем выбранная ячейка

Это мой код:

- (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]; 
} 
+0

Возможный дубликат [iOS UITableView Cell Selection] (http://stackoverflow.com/questions/11435753/ios-uitableview-cell-selection) – dasblinkenlight

ответ

0

Попробуйте для набора ноль для идентификатора повторного использования.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil]; 
0

Я думаю, что вы, возможно, уменьшили размер ячейки из IB и забыли установить высоту с помощью метода делегата. Попробуйте это

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 30.0; 
} 
Смежные вопросы