0

나는 여전히 아이폰 SDK에 익숙해지고있다.UITableViewCell 선택이 모든 셀에 유지됩니다!

이것은 내가 뭘하려고 오전입니다 :

나는있는 UIScrollView 및 각 스크롤 뷰는 jQuery과를 가지고 있는데 사용자 지정있는 UITableViewCell을 구현해야합니다.

처음에는 원하는 기능이 없지만 사용자가 행을 선택하여 스크롤하고 다음 스크롤보기에서 다른 선택을하고 계속합니다. 선택 항목을 유지하려면 나중에 사용자가 선택 항목을 변경할 수 있습니다.

그러나 내 경우에 무슨 일이있다 - 첫 번째 및 두 번째 UITableViews 괜찮아요, 선택한 행을 유지하지만 세 번째 UITableView있는 첫 번째 UITableView 동일한 "이미"선택한 행을 참조하십시오. 내가 선택한 것을보고 싶지 않아.

나는 바보 같은 짓을하고 있지만 무엇을 알아 내지 못했는지 알고 있습니다. 어떤 도움이라도 대단히 감사 할 것입니다.

덕분에, 여기 에이미

는 관련 데이터 소스 및 위임 방법이 있습니다.

 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSLog(@"%s", __FUNCTION__); 
static NSString * ChoiceTableCellIdentifier = @"ChoiceTableCellIdentifier"; 
choiceTableCell = (ChoiceTableCell *)[tableView dequeueReusableCellWithIdentifier:ChoiceTableCellIdentifier]; 
if(choiceTableCell == nil) 
{ 
    choiceTableCell = [[[ChoiceTableCell alloc] 
     initWithFrame:CGRectZero 
     reuseIdentifier:ChoiceTableCellIdentifier] autorelease]; 
} 
return choiceTableCell; 
} 


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSLog(@"%s", __FUNCTION__); 
int newRow = [indexPath row]; 
int oldRow = [lastIndexPath row]; 
if ((newRow != oldRow) || (newRow == 0)) 
{ 
     UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath]; 
    UIImageView *indicatorN = (UIImageView *)[newCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1]; 
    indicatorN.image = [UIImage imageNamed:@"selected.png"]; 
    newCell.backgroundView.backgroundColor = [UIColor clearColor]; 

     UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath]; 
    UIImageView *indicatorO = (UIImageView *)[oldCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1]; 
    indicatorO.image = [UIImage imageNamed:@"notSelected.png"]; 
    oldCell.backgroundView.backgroundColor = [UIColor clearColor]; 
     lastIndexPath = indexPath; 
} 
} 


 

답변

2

"selected.png"이미지가있는 셀을 다시 사용하고 있습니다. cellForRowAtIndexPath 메서드에서 마지막 선택에 따라 셀을 "선택"또는 "선택 취소"해야합니다. 즉 : indexPath가 lastIndexPath와 같으면 배경을 "selected.png"로 지정하고 그렇지 않으면 "noSelected.png"로 설정해야합니다. 셀을 다시 사용할 때는 이전 상태를 유지하므로 모두 초기화해야합니다.