Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView Section Index overlapping row delete button

After quite a lot searching around Google, Stackoverflow and apples documentation, I have almost given up.

I am making an app to index costumers and because of a potentially very long list, I use section index to navigate faster. My problem is shown in the picture below.

http://i.stack.imgur.com/i2tTx.png

When I drag an item to reveal the delete button, it is partially hidden below my section index bar.

I have no code setting tableview or tableviewcells width and the section index can't really be changed, as far as i am concerned.

EDIT:

The question is how I can have the tableview cells end before they get overlapped, so the delete button is fully visible.

EDIT 2:

I already tried setting the cell frame smaller without any luck.

cell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width-30, cell.frame.size.height);

I also tried the same with the tableview, but as it is in a UITableViewController it cannot be resized.

self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width-30, self.tableView.frame.size.height);
like image 691
Stjernegard Avatar asked Sep 28 '13 12:09

Stjernegard


2 Answers

As a simple work-around we resolved the visual overlap of the index by setting the background color of the index to clearColor.

self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];

* This looks visually better, but the index will still overlap your tableViewCell.

Another possible work-around would be to hide the index bar when entering edit mode:

// allow editing
[self.tableView setEditing:YES animated:YES];
// hides the index
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;
like image 139
Min Tsai Avatar answered Oct 24 '22 20:10

Min Tsai


The inEditMode method should do the trick. Below I embed a complete code that hides the index while editing and shows it again when the editing is done.

-(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];
}
like image 35
Alexey Avatar answered Oct 24 '22 22:10

Alexey