当我tableView
是不是在编辑模式下,我不希望用户能够接触到的细胞,并让它们突出显示选定单元格的背景。但是,因为我已将allowsSelectionDuringEditing
设置为YES,所以用户可以在编辑模式下选择单元格。的UITableView:仅在编辑模式下
我怎么只显示单元突出观点或颜色在编辑模式下,只有当?
当我tableView
是不是在编辑模式下,我不希望用户能够接触到的细胞,并让它们突出显示选定单元格的背景。但是,因为我已将allowsSelectionDuringEditing
设置为YES,所以用户可以在编辑模式下选择单元格。的UITableView:仅在编辑模式下
我怎么只显示单元突出观点或颜色在编辑模式下,只有当?
我想通了。这里是我的方法,设置tableView
编辑模式:
- (void)tableViewEdit {
if (self.tableView.editing) {
[self.editButton setTitle:NSLocalizedString(@"Edit", nil) forState:UIControlStateNormal];
self.tableView.allowsSelection = NO;
} else {
[self.editButton setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];
self.tableView.allowsSelection = YES;
}
[self.tableView setEditing:!self.tableView.editing animated:YES];
}//end
我以前也设置self.tableView.allowsSelection
为NO作为默认,所以进入编辑模式后,也只会是YES。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *[email protected]"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
//YOUR inits
}
if(self.editing){
[cell setSelectionStyle:UITableViewCellEditingStyleNone];
}else
[cell setSelectionStyle:UITableViewCellEditingStyleBlue];
return cell;
}
和
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(self.editing)return; //NO ACTION
}
这并不在我的经验工作,因为进入编辑模式下'cellForRowAtIndexPath'不会再次打来电话,细胞没有得到重绘,所以他们不知道自己在想是何时显示颜色在编辑模式下触摸。 – 2013-04-29 15:02:51
打开编辑模式时,如何重新载入表格? – iphonic 2013-04-29 18:03:57
这使得漂亮的动画消失。当然,这确实有效,但我想要动画。 – 2013-04-29 18:55:21
有趣的场景,幸运的是,它是如此简单:
// -tableView:shouldHighlightRowAtIndexPath: is called when a touch comes down on a row.
// Returning NO to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
return self.isEditing;
}
你可以从苹果的评论shouldHighlight看到的是在选择过程中的第一步,所以这是阻止它的情况下,地方表正在编辑。
你会更好地覆盖setEditing,或者看到我的答案更简单。 – malhal 2015-07-24 11:20:44