You've got to override layoutSubviews and do something like the following. And don't forget to set the indentation level to something greater than 0 :) For custom cells the indentation level is not applied by default.
Up vote 2 down vote favorite 1 share g+ share fb share tw.
I have made a custom UITableViewCell, and done it properly (adding everything to contentView, and overriding layoutSubviews so my subviews are relative to contentView. Bounds). When the user presses the Edit button, the table indents to allow room for the red delete sign.
This is fine, but the default amount of indentation is too much, and ruins the look of my custom cell. How can I reduce the amount of indentation? SetIndentationLevel and tableView:IndentationLevelForRowAtIndexPath don't seem to do anything.
(Someone asked a similar question here, but it was never resolved). Iphone cocoa-touch uitableview uitableviewcell link|improve this question asked Apr 19 '11 at 7:48Ric Levy400113 84% accept rate.
You've got to override layoutSubviews and do something like the following. And don't forget to set the indentation level to something greater than 0 :) For custom cells the indentation level is not applied by default. To avoid indentation for the single swipe to delete gesture you'll have to do a but more work.
There is a state which reflects the editing state of the cell. It is not public but can be accessed with - (void)willTransitionToState:(UITableViewCellStateMask)aState, so storing it in a property does the work for layoutViews. Apple's documentation for willTransitionToState: Note that when the user swipes a cell to delete it, the cell transitions to the state identified by the UITableViewCellStateShowingDeleteConfirmationMask constant but the UITableViewCellStateShowingEditControlMask is not set.
Header file int state; ... @property (nonatomic) int state; ... cell implementation @synthesize state; ... - (void)layoutSubviews { super layoutSubviews; self.contentView. Frame = CGRectMake(0, self.contentView.frame.origin. Y, self.contentView.frame.size.
Width, self.contentView.frame.size. Height); if (self. Editing && ((state & UITableViewCellStateShowingEditControlMask) &&!(state & UITableViewCellStateShowingDeleteConfirmationMask)) || ((state & UITableViewCellStateShowingEditControlMask) && (state & UITableViewCellStateShowingDeleteConfirmationMask))) { float indentPoints = self.
IndentationLevel * self. IndentationWidth; self.contentView. Frame = CGRectMake(indentPoints, self.contentView.frame.origin.
Y, self.contentView.frame.size. Width - indentPoints, self.contentView.frame.size. Height); } } - (void)willTransitionToState:(UITableViewCellStateMask)aState { super willTransitionToState:aState; self.
State = aState; }.
Worked perfectly. Thanks! – Ric Levy Apr 19 '11 at 8:41 Ah... I have noticed one problem.
The indentation is the same amount whether the user presses the edit button or swipes to delete. Is there any way of intercepting the swipe-to-delete and telling it to do something different? – Ric Levy Apr 19 '11 at 8:56 Ah ok, I just edited my code and provided a simple solution.
Have a look. – Nick Weaver Apr 19 '11 at 9:15 Ignore what I wrote here a second ago - it works perfectly. Thanks!
– Ric Levy Apr 19 '11 at 9:48 @Nick sorry - I was right the first time. Unfortunately this doesn't entirely work. The cell now stays still when sliding to delete, and it indents just the right amount when pressing the edit button.
But when I press the left-hand red button (to make 'delete' appear on the right), the cell suddenly slips further to the right again. Do you have any idea why this might be? – Ric Levy Apr 19 '11 at 16:36.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.