2010-04-30 65 views
2

我有UITableView。我定製了細胞高度(80.0f)。我有4個標籤(UILabel)和1個圖像(UIImage)和3個按鈕(UIButton)。其中一個按鈕是刪除按鈕。通過觸摸圖像上的單元格或按鈕(播放按鈕),可以加載和播放視頻。如何使用單元格中的自定義按鈕刪除UITableView中的單元格?

我需要通過觸摸刪除按鈕來刪除單元格。 我寫了一個刪除按鈕選擇器。我可以從庫中刪除視頻。但是如何從表中刪除單元格?

謝謝。 下圖顯示了我的程序的刪除按鈕。

alt text http://www.freeimagehosting.net/uploads/c2036dee19.png

回答

2

當我這樣做時,我得到了解決方案。

-(void)deleteClicked:(id)sender 
{ 
    UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview]; 
    clickedButtonPath = [self.tableView indexPathForCell:clickedCell]; 

    NSArray *arrayDelete = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectoryD = [arrayDelete objectAtIndex:0]; 

    NSDictionary *dictOfplist1 = [contentArray objectAtIndex:clickedButtonPath.row]; 

    //To remove the videos from Documents folder  
    NSString *pathTemp1 = [documentsDirectoryD stringByAppendingString:[dictOfplist1 objectForKey:@"fileVideoE"]]; 
    BOOL succeed1 = [[NSFileManager defaultManager] removeItemAtPath:pathTemp1 error:nil]; 

    //To remove the images shown in cell from Documents folder. 
    NSString *pathTemp2 = [documentsDirectoryD stringByAppendingString:[dictOfplist1 objectForKey:@"fileImageE"]]; 
    BOOL succeed2 = [[NSFileManager defaultManager] removeItemAtPath:pathTemp2 error:nil]; 

    //To remove the data from the plist which is in Documents folder. 
    NSString *pathDelete = [documentsDirectoryD stringByAppendingString:@"/details.plist"]; 
    [contentArray removeObjectAtIndex:[clickedButtonPath row]]; 
    [contentArray writeToFile:pathDelete atomically: YES]; 

    //To reload the data of the plist after deleting the items from it. 
[self.tableView reloadData]; 
}  

每一件事情是罰款該單元被刪除,在plist中的數據被刪除的文檔文件夾中的視頻和圖像將被刪除。

這是當我刪除第二行時的圖像。
謝謝。

alt text http://www.freeimagehosting.net/uploads/f3c96ae3a7.png

1

電話:

[self.tableView reloadData]; 

你需要做一些研究的MVC成語。

3

如果模型更新正如你所說,使用表格視圖這種方法來刪除與動畫單元:

- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths 
       withRowAnimation:(UITableViewRowAnimation)animation 

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/deleteRowsAtIndexPaths:withRowAnimation

表視圖將清理電池爲你。

請注意,commitEditingStyle:方法僅在桌面視圖的刪除按鈕(通過編輯模式或刷卡刪除方式獲取的按鈕)被觸摸時調用。從你的問題,這聽起來像你有一個自定義按鈕,這就是爲什麼這個方法沒有被調用。你可以自己調用它,但我不會推薦它,因爲它只能由tableview自己調用。

相關問題