我正在使用
SectionIndexTitlesForTableview
方法为Tableview设置标题。当我滑动一个单元格时,删除按钮会出现在这些标题旁边,看起来很奇怪。如何在删除按钮出现时隐藏这些索引标题,并在删除按钮消失时显示它们。SectionIndexTitlesForTableview
方法为Tableview设置标题。当我滑动一个单元格时,删除按钮会出现在这些标题旁边,看起来很奇怪。如何在删除按钮出现时隐藏这些索引标题,并在删除按钮消失时显示它们。inEditMode
方法在编辑表格时隐藏索引。
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self inEditMode:YES];
}
-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self inEditMode:NO];
}
//on self.editButtonItem click
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
[self inEditMode:editing];
}
-(void)inEditMode:(BOOL)inEditMode{
if (inEditMode) { //hide index while in edit mode
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;
}else{
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMin;
}
[self.tableView reloadSectionIndexTitles];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [tableView isEditing] ? nil: @[@"A",@"B",@"C"];
}
- (void)setEditing:(BOOL)editing
{
[super setEditing:editing];
[self reloadSectionIndexTitles];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
_someBoolean = YES;
[tableView reloadData];
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
_someBoolean = NO;
[tableView reloadData];
}
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return _someBoolean ? nil : _yourTitlesArray;
}