2012-11-01 4 views
0

데이터 및 이미지가 UITableView의 셀에 있습니다. 특정 셀의 이미지를 변경하고 싶습니다. 각 셀에 코드가 있습니다.특정 셀에 대한 UITableView의 반복

셀에 대한 tableview를 반복하는 방법을 찾을 수 없습니다.

여기 내 테이블 뷰 기능의 스냅 샷입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *cellText = nil; 

    NSArray *keys = [[[self packageItems] allKeys] 
        sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 
    cellText = [keys objectAtIndex:[indexPath row]]; 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier:CellIdentifier]; 
     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
    } 
    cell.imageView.image=[UIImage imageNamed:@"checkbox.png"]; 
    //cell.imageView.image=[UIImage imageNamed:@"checkbox-checked.png"]; 

    return cell; 
} 

내가 cell.imageView.image = 셀에 화상 변경할 다른 함수가 [있는 UIImage imageNamed를 @ '체크 박스-checked.png "];

- (void)OnAction 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    NSIndexPath *indexPath = [[NSIndexPath alloc] initWithIndex:0]; 
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath ]; 
    cell.imageView.image=[UIImage imageNamed:@"checkbox-checked.png"]; 

} 

답변

0

당신이 방금 실제 셀을 수정, 새로운 셀을해야 그나마 기능을 테이블보기에 뭔가를 변경하는 습관합니다. 그냥 cellForRowAtIndexPath 대리자 상태를 확인하십시오

if(indexPath == indexToModify) { 
    cell.imageView.image=[UIImage imageNamed:@"checkbox-checked.png"]; 
} else { 
    cell.imageView.image=[UIImage imageNamed:@"checkbox.png"]; 
} 

과의

- 결국 (무효)의 OnAction 방법을 사용 :

[self.tableView reloadData]; 
+0

감사합니다 사랑, 내 문제가 indexToModify을 찾는 것입니다. 내 OnAction 함수에서 키를 가져오고이 키는 각 셀 키와 비교해야합니다. 일치하는 경우에만 이미지를 변경하고 싶습니다. 당신의 대답은 나에게도 도움이된다. – Krishan

관련 문제