2013-09-03 2 views
5

나는 아래의 기본 메일 응용 프로그램과 같은 여러 행을 선택할 수 있도록하려면 설정되어있을 때있는 UITableViewCell을 선택할 수 없습니다 :가있는 TableView setEditing이

enter image description here

나는

를 호출하는 버튼라는 편집이 위 그림과 같이
[self.myTableView setEditing:YES animated:YES] 

enter image description here

편집 버튼을 성공적으로 메일 응용 프로그램과 같은 세포의 왼쪽에 동그라미를 보여줍니다. 그러나 실제로 행 중 하나를 선택하면 아무 일도 일어나지 않습니다. 빨간색 체크 표시가 예상대로 원에 표시되지 않습니다. 빨간색 체크 표시가 나타나지 않는 이유는 무엇입니까?

#pragma mark - UITableViewDataSource Methods 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"]; 
    } 

    cell.textLabel.text = @"hey"; 

    return cell; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 3; 
} 

#pragma mark - UITableViewDelegate Methods 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 3; 
} 

#pragma mark - Private Methods 

- (IBAction)editButtonTapped:(id)sender { 
    if (self.myTableView.editing) { 
     [self.myTableView setEditing:NO animated:YES]; 
    } 
    else { 
     [self.myTableView setEditing:YES animated:YES]; 
    } 
} 

답변

14

명시 적으로 편집 모드에서 활성화되어 있어야 선택 설정해야합니다 :에 따르면

[self.tableView setAllowsSelectionDuringEditing:YES]; 

또는

[self.tableView setAllowsMultipleSelectionDuringEditing:YES]; 

docs : 이러한 속성은 기본적으로 NO으로 설정됩니다. 이 속성의 값이 YES 인 경우

, 사용자는 편집하는 동안 행을 선택할 수 있습니다. 기본값은 NO입니다. 모드에 관계없이 셀의 선택을 제한하려면 allowsSelection을 사용하십시오.

또한 다음 코드 스 니펫은 선택한 행을 즉시 선택 취소하기 때문에 선택에 문제를 일으킬 수 있습니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 
+0

감사합니다! 이것은 그 것이다. 또한 테이블보기 (테이블보기 컨트롤러 제외)에서 IB에서 "편집 중 : 편집 중 단일 선택"으로 변경할 수 있습니다. – jrc