2011-11-04 21 views
2

刪除行,我有地方,如果用戶輸入數據的行會與數據更新的應用程序在UITableView的

我可以使用一個單一按鈕說「刪除」,點擊後刪除所有行桌面視圖一次。

回答

3

做一個按鈕,在按鈕的操作方法

-(IBAction)deleteRows 
{ 
    [array removeAllObjects]; 
    [tableview reloadData]; 
} 
7

是的,你可以做到這一點。首先從您的數據源中刪除所有數據,然後重新加載您的表。例如。 -

[yourArrayDataSource removeAllObjects]; 
[yourTable reloadData]; 

設置動畫的行刪除 - 在IBAction方法&鏈接它這樣做是爲了您的UIButton。只要你按下按鈕,你將有一個平滑的令人敬畏的動畫,使所有的行淡出。

-(IBAction)deleteRows 
{ 
    [yourTable beginUpdates]; 
    for(int i=0; i<[yourArrayDataSource count]; i++) 
    { 
     indexPath = [NSIndexPath indexPathForRow:i inSection:0]; 
     [self.searchResTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    [yourTable endUpdates]; 
} 

有,你可以使用這裏 -

UITableViewRowAnimationBottom 
UITableViewRowAnimationFade 
UITableViewRowAnimationMiddle 
UITableViewRowAnimationNone 
UITableViewRowAnimationRight 
UITableViewRowAnimationTop 
+0

你可以給我一點點code.so,我可以從那裏管理它 – Chandu

+0

好thnx會嘗試它 – Chandu

3

Srikar的回答讓我在正確的軌道上各種動畫,但創建了大量額外的單個項目數組,並且調用deleteRowsAtIndexPaths遠遠超過所需的數量。

-(void)clearTable 
{ 

    NSMutableArray *indexPaths = [NSMutableArray array]; 
    for(int i=0; i<[self.myArray count]; i++) 
    { 
     NSIndexPath *anIndexPath = [NSIndexPath indexPathForRow:i inSection:0]; 
     [indexPaths addObject:anIndexPath]; 
    } 

    [self.myTableView beginUpdates]; 
    [self.myTableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; 
    self.myArray = [NSArray array]; 
    [self.myTableView endUpdates]; 

}