有没有人可以请解释一下如何正确实施tableView:commitEditingStyle:forRowAtIndexPath:
方法,以便我可以正确删除支持数组中的项目并仅显示尚未删除的项目?正确地从UITableView中删除一个项目
这是我到目前为止有:
@interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
IBOutlet UITableView *tableView;
NSArray *allItems;
NSMutableArray *displayItems;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
allItems = [[NSArray alloc] initWithObjects:@"One",@"Two",@"Three",@"Four",@"Five",@"Six",@"Seven", nil];
displayItems = [[NSMutableArray alloc] initWithArray:allItems];
}
-(UITableViewCell*) tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = [displayItems objectAtIndex:indexPath.row];
return cell;
}
@end
谢谢!非常感激! – nemesis 2012-03-19 13:05:33
崩溃:由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效的更新:在第0节中的行数无效。更新(7)后现有节中包含的行数必须等于在更新前包含在该部分中的行(7),加上或减去从该部分插入或删除的行数(0插入,1删除)以及加或减移入或移出该部分的行数(0移动中,0移出)。' – nemesis 2012-03-19 16:40:46