2010-07-14 1 views
2

UITableView를 사용하여 검사 목록 프로그램을 만들고 모든 항목을 구현하여 선택 표시를하고 확인 표시를합니다. 그러나 셀에서 스크롤 할 때. 확인 표시가 사라집니다.UITableView 검사 목록

나는 다음과 같은 코드가 있습니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"CellIdentifier"; 

// Dequeue or create a cell of the appropriate type. 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

} 

// Configure the cell. 
if(tableView == Table1){ 

    switch(indexPath.section){ 
     case 0: 
      cell.textLabel.text =[array1 objectAtIndex:indexPath.row]; 
      break; 
     case 1: 
      cell.textLabel.text = [array2 objectAtIndex:indexPath.row]; 
      break; 
     case 2: 
      cell.textLabel.text = [array3 objectAtIndex:indexPath.row]; 
      break; 
    } 

    //cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row]; 
} 

//if([indexPath compare:[selectedArray objectAtIndex:i]] == NSOrderedSame){ 
if([selectedArray containsObject:cell]){ 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
}else{ 
     cell.accessoryType = UITableViewCellAccessoryNone; 
} 
//} 
if(tableView == sauceTable){ 
    cell.textLabel.text = [array4 objectAtIndex:indexPath.row]; 
} 

return cell;} 

그리고 :

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
UITableViewCell *c= [aTableView cellForRowAtIndexPath: indexPath]; 
c.accessoryType = UITableViewCellAccessoryCheckmark; 
[selectedArray addObject: c]; 
} 

어떤 아이디어?

답변

1

해결. selectionArray에 대해 UITableViewCell 대신 NSIndexPath를 사용했습니다.

+0

이 문제를 해결하는 데 사용한 일부 코드를 표시 할 수 있습니까? –