Three20是一個偉大的庫。它使表格的工作變得非常簡單。但我注意到的一個缺陷是刪除了行,並帶有動畫。我花了很多時間試圖做到這一點,這是我在做什麼:如何刪除TTTableViewController中的行(Three20)
// get current index patch
UITableView* table = [super tableView];
NSIndexPath *indexPath = [table indexPathForSelectedRow];
//delete row in data source
TTListDataSource * source = (TTListDataSource *)self.dataSource;
[source.items removeObjectAtIndex:indexPath.row];
// delete row from the table, with animation
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
此代碼後運行出現錯誤:[NSCFArray objectAtIndex:]:指數(0)超出範圍(0)
我正在使用從TTTableViewController繼承的類。我沒有實現DataSourceDelegate或TableViewDelegate,因爲我儘可能地使用了Three20。所以,這是我如何創建數據源:
for(NSDictionary *album in (NSArray *)albums){
TTTableRightImageItem *item = [TTTableRightImageItem itemWithText:@"name"
imageURL:@"image url"
defaultImage:nil
imageStyle:TTSTYLE(rounded)
URL:@"url of selector where I actually catch the tap on a row"];
[tableItems addObject:item];
}
self.dataSource = [TTListDataSource dataSourceWithItems:tableItems];
我看了這篇文章(article),但它並不能幫助:(
所以,我知道,這是從這個網站的大師很簡單。你能不能給我如何做到這一點
感謝
好的。這是重要的評論。我在行「NSIndexPath * indexPath = [table indexPathForSelectedRow];」之後加了一行「table.editing = YES;」。結果是一樣的:( – Dmitry 2009-12-06 19:49:48
類TTSectionedDataSource不足以在可編輯表中使用,因爲它沒有實現tableView:commitEditingStyle:forRowAtIndexPath。Subclass TTSectionedDataSource並實現ableView:commitEditingStyle:forRowAtIndexPath。在這個方法中刪除該項目,然後調用didDeleteObject。這個方法會通知你的控制器並執行動畫。 – lyonanderson 2009-12-06 20:30:22
其實我只需要用動畫程序去除行,就像這裏:http://stackoverflow.com/questions/915095/how-to-delete-a我注意到在TTSectionedDataSource中有「 - (void)removeItemAtIndexPath:(NSIndexPath *)indexPath」方法,但它拋出一個錯誤!!也許這是Three20中的一個錯誤 – Dmitry 2009-12-06 21:48:22