我是一个可滑动的 tableView 单元格,在该单元格中有一个用于删除该行的按钮。我的方法中有这段代码来删除该行。该行的内容已从 DataSource 中正确删除,但我在隐藏和重新加载我的 tableView 时遇到了麻烦。这是我的代码:
- (void)deleteElementAtIndexPath:(NSIndexPath *)indexPath {
[dateTableView beginUpdates];
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
listTitles = [[NSMutableArray alloc] init];
listTitles = [[user objectForKey:@"listTitles"] mutableCopy];
[listTitles removeObjectAtIndex:indexPath.row];
[user setObject:listTitles forKey:@"listTitles"];
[user synchronize];
[dateTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[dateTableView endUpdates];
[dateTableView reloadData];
}
我的班级有委托和数据源协议。这也是我的委托方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"reloading...numberofsection");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"reloading...numberofrowsinsection");
return [listTitles count];
}