【发布时间】:2014-02-28 22:19:21
【问题描述】:
我非常困惑。我查看了几篇帖子,试图弄清楚如何做到这一点。我想做的是检测何时点击UITableViewCell,然后在该行的正下方插入一行,并带有一个菜单。
我实现了检测被点击的项目,但我不知道如何在刚刚被点击的行下方插入新行。
这是处理点击单元格的方法。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
indexPath = nil;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
Locations *location = nil;
if (self.searchDisplayController.active) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
location= [self.searchResults objectAtIndex:indexPath.row];
NSLog(@"location : %@" ,location.locationName);
[self.locations addObject:@"New Entry"];
[tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:YES];
//[self.tableViewForScreen insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
location = [self.locations objectAtIndex:indexPath.row];
NSLog(@"location : %@" ,location.locationName);
[tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// set the tapped item pointer equals to the locations mutable array variable wich essentially is the
// data source of the table view.
//Locations *tappedItem =[self.locations objectAtIndex:indexPath.row];
//access the location name and print to log.
}
显然它在插入部分失败
[tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:YES];
有人可以帮帮我吗?
错误如下。
原因:'无效更新:第 0 节中的行数无效。 更新后现有部分中包含的行数 (154) 必须等于该节之前包含的行数 更新(154),加上或减去插入或删除的行数 从该部分(插入 1 个,删除 0 个)并加上或减去数字 移入或移出该部分的行数(0 移入,0 移出)。'
这是我看过的帖子。 UITableView action row http://adcdownload.apple.com//videos/wwdc_2011__sd/session_125__uitableview_changes_tips_tricks.m4v
【问题讨论】:
标签: objective-c uitableview ios7