题
在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继承的类。而且因为我使用的Three20尽可能我没有实现DataSourceDelegate或TableViewDelegate。所以,这是我如何创建数据源:
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];
我读这篇文章(文章),但它没有帮助:(
所以,我知道,这是从这个网站的大师很简单。你能不能给我如何做到这一点先进的样品
感谢。
解决方案
我发现的第一件事情是,你删除从表中的一行时,该表是不是在编辑模式。
其他提示
我也得到了“EXC_BAD_ACCESS”在model:didDeleteObject:atIndexPath:
,但我得到的问题就迎刃而解了。
要在您需要实现你的DataSource实现这样一个tableView:commitEditingStyle:
删除TTTableViewController行:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { id object = [[self.items objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; [self.model didDeleteObject:object atIndexPath:indexPath]; } }
您还需要实现在你的数据源tableView:willRemoveObject:atIndexPath:
:
- (NSIndexPath*) tableView:(UITableView *)tableView willRemoveObject:(id)object atIndexPath:(NSIndexPath *)indexPath { // delete the object [object deleteFromDB]; // removeItemAtIndexPath returns YES if the section is removed if ([self removeItemAtIndexPath:indexPath andSectionIfEmpty:YES]) { // remove an index path only to that section return [NSIndexPath indexPathWithIndex:indexPath.section]; } else { return indexPath; } }
关键是要改变你回到只有NSIndexPath
包含部分的它得到空。然后在TTTableViewController代码除去部,而不是细胞内。
HTH
不隶属于 StackOverflow