2009-07-22 5 views
5

나는 UITableView를 가지고 있으며 행에서 손가락을 쓸어 넘기거나 쓸어 넘겨 줄 때 행을 지울 수있는 기능을 사용자에게 제공하려고합니다. 원형의 빨간 버튼에 -ve 기호가있는 편집 스타일을 알고 있습니다. 그러나 flicking 스타일을 구현하는 방법. 나는 그것을 사용하는 많은 응용 프로그램을 보았습니다. 그래서 사과는 그것을 위해 모든 내장 된 델리게이트를 제공 할 것입니다. 또는 우리는 그것을 위해 독자적인 컨트롤러를 작성해야합니다.iPhone에서 표의 행을 삭제하는 방법

+0

당신은 이미 알고있는 방법을 말해 줄 수 있습니까? coz 나는 그것을 구현하고 싶습니다. – rptwsthi

답변

32

이이 삭제 슬쩍 상호 작용에 대한 액세스를 제공 할 것입니다 당신이 테이블 뷰 대리인에게

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

방법을 구현해야 영향을 미칩니다. 스 와이프 상호 작용이 사용자로부터 조금 숨겨지기 쉽기 때문에 일반적으로 삭제가 가능한 테이블 뷰의 편집 상호 작용을 제공합니다. 예를 들어

: 도움이

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView beginUpdates];  
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
    // Do whatever data deletion you need to do... 
    // Delete the row from the data source 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop]; 
    }  
    [tableView endUpdates]; 
} 

희망.

+0

덕분에 친구를 알 수 없다. – WaaleedKhan

+1

withRowAnimation : 예가 잘못되었습니다. 예를 들어 열거 형을 사용해야합니다. withRowAnimation : UITableViewRowAnimationTop – ozba

+0

'... UITableViewRowAnimationTop];을'... UITableViewRowAnimationAutomatic];으로 변경하는 것을 고려하십시오. 이것은 유효하지 않은 편집 (주석이어야 함)에서 수행되었으므로 되돌 렸습니다. 이것이 맞으면 그에 따라 솔루션을 업데이트하는 것을 고려하십시오. –

2

저는이 작업을 수행하는 샘플 응용 프로그램이 거의 확실합니다. 곧 더 구체적인 대답이 올 것이다.

업데이트 : iPhoneCoreDataRecipes 아마도 당신이 찾고있는 것을 정확하게 얻을 수 있습니다. 주제에

, 여기에 달콤한 제공하는 방법 중 하나입니다

// If I want to delete the next 3 cells after the one you click 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSMutableArray* indexPaths = [NSMutableArray array]; 
    for (int i = indexPath.row + 3; i < indexPath.row + 3; i++) 
    { 
    [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]]; 
    } 

    [tableView beginUpdates]; 
    [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 
    [tableView endUpdates]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

내가 거기에 당신이 원하는 것을 달성하기 쉬운 방법이지만, 다시 이것은 아주 쉽게 생각합니다. 유일한 어려움은 자신을 지우는 것일 수도 있습니다 ... 세그 폴트를 조심하십시오. 슬쩍을 얻기 위하여

관련 문제