Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent indentation of UITableViewCell (contentView) while editing

Is it possible to keep the contentView.frame always the same, regardless of tableView.editing? I already tried to override layoutSubviews and willTransitionToState but those options fizzled out too. I can't seem to be able to change the width of the contentView. Or maybe my approach ist just plain impossible ... Maybe there is another way to solve this.

The behaviour I want to achieve is the following: I want the standard textLabel of a UITableViewCell to be always indented and not change position when the tableView enters editing mode. The problem I will probably face is that the behaviour of the detailTextLabel will have to be corrected (e.g. truncation of text if textLabelcontent is too long). The reason why I don't want to implement my own UILabelis because a custom subviews will decrease the scrolling performance by a significant amount.

I hope that anyone already implemented something like this in their UITableViewand could show me a solution to this tedious problem. Thanks in advance!

EDIT: I'm dealing with a UITableView in plain and not grouped style.

like image 720
fscheidl Avatar asked Apr 26 '11 11:04

fscheidl


1 Answers

Use the UITableViewDelegate method:

- (BOOL)tableView:(UITableView *)tableView          shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath  {      return NO; } 

This will work for both grouped and non-grouped UITableView types. However, if you have a grouped tableview, you can use this property on the cell:

cell.shouldIndentWhileEditing = NO; 
like image 91
Usman.3D Avatar answered Sep 21 '22 10:09

Usman.3D