Tableview单元格选择问题

iPr*_*mer 0 iphone uitableview

您好我正在使用分组表视图并选择具有蓝色选择样式的Tableview的单元格.

但是当选择单元格并转到下一个视图并再次回到上一个视图时,仍然选择单元格,如果我选择另一个单元格,则显示2个单元格已选中.

在我的代码中查看图像及其下方:

在此输入图像描述

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    JobViewTableCell *cell = (JobViewTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            [[NSBundle mainBundle] loadNibNamed:@"iPadJobViewCell" owner:self options:nil];
            cell = self.JobViewcell;
        }
        else {
        [[NSBundle mainBundle] loadNibNamed:@"JobViewTableCell" owner:self options:nil];
        cell = self.JobViewcell;

        }
    }


    [cell setJobID:[NSString stringWithFormat: @"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]JobId]]];
    [cell setJobTitle:[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Title]]];

    NSString *newDate =[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Date]];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM/dd/yyyy h:mm:ss a"];
    NSDate *myDate = [dateFormat dateFromString:newDate];
    [dateFormat setDateFormat:@"MM/dd/yyyy"];

    NSString *str = [dateFormat stringFromDate:myDate];

    NSLog(@"%@",str);



    [cell setJobDate:[NSString stringWithFormat:@"%@",str]];
    [cell setLocation:[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Location]]];
    [dateFormat release];
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

请帮忙

Wri*_*sCS 6

在tableView的didSelectRowAtIndexPath方法中,添加deselectRowAtIndexPath:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
    . . .
}
Run Code Online (Sandbox Code Playgroud)