2011-06-11 4 views
2

사용자가 작업을 트리거하는 셀을 탭하면 사용자 상호 작용을 사용하지 않도록 설정 한 다음 작업이 완료되면 사용자 상호 작용을 다시 활성화하려고합니다. 누군가 이걸 어떻게하는지 말해 줄 수 있니?UITableView의 개별 셀 선택 해제하는 방법?

답변

8

그냥있는 TableView의 대리자 메서드의 조건을 확인 실행 중일 때 당신은 selectionStyle을 만들 수 있습니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *categoryIdentifier = @"Category"; 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    //Way to stop to choose the cell selection 
    if(indexpath.row == 0){ 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     // OR 
     cell.userInteractionEnabled=False; 
    } 
    //while rest of the cells will remain active, i.e Touchable 

    return cell; 

} 
+0

이유 indexpath.row == 0? – lilzz

+0

이것은 셀 선택을하지 않는 특정 셀에만 적용됩니다. 그렇지 않으면 이것을 가질 필요가 없습니다;) –

+0

"cell.userIneractionEnabled = False;"에 동의합니다. 선택 스타일을 변경하면 사용자 상호 작용이 비활성화되지 않습니다. – helioz

1

동작이 시작될 때 true로 설정 한 BOOL 변수를 추가하기 만하면됩니다. 그런 다음 해당 인덱스 경로에 대한 변수가 현재 true 일 때 nil을 반환하도록 테이블 뷰 대리자의 -[tableView:willSelectRowAtIndexPath:] 메서드를 구현합니다.

1

또는 조치가

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
관련 문제