2013-03-18 2 views
0

JITidePanel 컨트롤러 (https://github.com/gotosleep/JASidePanels) 안에 퍼팅하는 UITableview가 있습니다. 내 init 메서드에서 대리자 및 데이터 소스를 설정하고 canEditRowAtIndexPath 메서드를 구현했으며 스 와이프 할 때 호출되고 있습니다. tableview 셀에 있지만 시각적으로 아무 것도 발생하지 않습니다. 다른 질문을 살펴본 후 제안 사항을 모두 구현했지만 삭제 버튼을 표시 할 수 없습니다. 누구든지이 행동을 일으키는 원인을 알 수 있습니까?UITableViewCell 삭제 단추가 나타나지 않습니다.

답변

7

tableView:editingStyleForRowAtIndexPath: 대리자 메서드와 tableView:commitEditingStyle:forRowAtIndexPath: 데이터 원본 메서드를 구현해야합니다. 이러한 옵션이 없으면 삭제가 셀에 표시되지 않습니다.

tableView:canEditRowAtIndexPath: 데이터 소스 방법 (적어도 적절한 행에 대해)에서 반환한다고 가정합니다.

+0

결국 나는이 사실을 알게되었습니다. 이 두 가지 방법을 구현하면 효과가 있기 때문에이 대답을 선택했습니다. 이 두 가지 방법을 구현했지만 삭제 단추는 JASidePanel의 중앙 패널 컨트롤러 아래에 숨겨져 있습니다 ... 나는 방금 tableview의 너비를 줄여야했고 나타났습니다 .. – AFraser

+0

@Afraser - 사실, 귀하의 의견은 내 대답을 도왔습니다. 내 문제는 매우 유사했습니다 (마스터보기의 오른쪽면 (사용자 정의보기 컨트롤러에서) 세부보기에 의해 가려졌습니다). 귀하의 질문에 JASidePanel 컨트롤러에 대한 언급이 있기 때문에 나는 확실히 대답으로 제시 할 것입니다. – Animal451

1

셀을 삭제할 때이 클래스의 고유 한 방법을 사용해 보셨습니까?

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (UITableViewCellEditingStyleDelete) { 
     int k = [[tempArray objectAtIndex:indexPath.row] intValue]; 

     //Remove object from index 'k'. 
    } 
} 

도움이 될 수 있습니다.

감사합니다.

0

TableViewCell을 스 와이프 할 때 UITableView에 대한 삭제 작업을 수행하려면. 다음과 같은 세 가지 방법을 구현해야합니다. -

이 방법은 TableViewCell을 스 와이프 할 때 삭제 버튼을 표시합니다.

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
     editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSUInteger row = [indexPath row]; 
    NSUInteger count = [posts count]; 

    if (row < count) { 
    return UITableViewCellEditingStyleDelete; 
    } else { 
    return UITableViewCellEditingStyleNone; 
    } 
} 

사용자가 TableViewCell의 강타와 슬쩍 행에 행을 삭제할 때이 메소드가 불려은 삭제 버튼을 눌러에 삭제됩니다.

- (void)tableView:(UITableView *)tableView 
     commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
     forRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSUInteger row = [indexPath row]; 
    NSUInteger count = [posts count]; 

    if (row < count) { 
    [posts removeObjectAtIndex:row]; 
    } 
} 

마지막으로이 메서드는 행을 삭제 한 후 테이블 뷰를 업데이트하기 위해 호출됩니다.

- (void)tableView:(UITableView *)tableView 
        didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { 

    [self updateViewTitle]; 
    [tableView reloadData]; 
} 
관련 문제