【发布时间】:2010-07-05 10:09:16
【问题描述】:
尝试从 UITableView 中删除行时遇到问题: UITableView 从 NSMutableArray 中获取行数:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [alertsArray count];
}
我以这种方式将对象添加到 NSMutableArray:
- (void)saveButton:(id)sender {
[alertsArray addObject:
[self.tableView reloadData];
}
使用此代码,我允许删除行:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[self.tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[alertsArray removeObjectAtIndex:indexPath.row];
[tableView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
由于某种原因,当尝试删除行时,应用程序崩溃了。
谢谢!
【问题讨论】:
标签: iphone uitableview nsmutablearray