当用户用以下代码将表切换到编辑模式时,我将向UITableView部分添加一行:
- (void) setEditing:(BOOL) editing animated:(BOOL) animated {
[super setEditing:editing animated:animated];
if (editing) {
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject: [NSIndexPath indexPathForRow:0 inSection:SECTION_SUPPLIERS]] withRowAnimation:UITableViewRowAnimationFade];
}
}目标是创建一个“添加新供应商.”划。但是,当表想获得编辑样式以便可以添加正负图标时,我就有问题了。
- (UITableViewCellEditingStyle) tableView:(UITableView *) tableView editingStyleForRowAtIndexPath:(NSIndexPath *) indexPath {
return ([self.tableView isEditing] && indexPath.row == 0) ? UITableViewCellEditingStyleInsert : UITableViewCellEditingStyleDelete;
}顺序似乎是这样的:
再次触发对编辑样式的另一个查询。
因此,如果我使用这个序列,并使用行号和tableView isEditing来决定编辑样式图标,我将得到添加新的和当前的供应商行,并在它们上加上图标。
插入一行并指定适当的编辑样式的最佳方法是什么?添加新行加上,对任何其他行都指定减号?
发布于 2011-02-23 13:59:33
你试过把你的“添加新.”在底部而不是在顶部划船?与其检查[indexPath row] == 0,不如检查[indexPath row] == [items count],tableView:numberOfRowsInSection:实现如下所示:
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
int numberOfRows = [items count];
if ([self isEditing]) {
numberOfRows++;
}
return numberOfRows;
}这就是iPhone编程中的例子:大Nerd牧场指南的工作原理。
https://stackoverflow.com/questions/5091720
复制相似问题