2011-09-09 79 views
0

你好我正在使用分组表格视图并选择Tableview的单元格与blueselection样式。Tableview单元格选择问题

但当选择单元格,然后转到下一个视图,并再次回到以前的观点细胞仍处于选中状态,如果我选择是显示选择2cells另一个单元。

看到的图像与下面在我的代码:

enter image description here

// 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; 
} 

请帮助

回答

6

在您的tableView的didSelectRowAtIndexPath方法,添加deselectRowAtIndexPath

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO]; 
    . . . 
} 
+0

谢谢..它工作正常 – iProgrammer