Determine whether UITableViewCell is editing from “swipe” or “self.editButton”

I'm trying to determine whether a UITableViewCell subclass is in edit mode from a user's swipe (in which case I don't need to indent my subviews) or from the user pressing the "Edit" button associated with the UITableViewController. (In which case I do.)

I know it's possible from a cell's perspective, since the self.textLabel view automatically indents properly. I have tried:

-(void)layoutSubviews {
   [super layoutSubviews];

   CGRect labelFrame = self.textLabel.frame;
   labelFrame.origin.x += 5;
   myCustomUILabel.frame = labelFrame;
}

But my custom label does not properly indent. (Though the self.textLabel view does?)

I would like to avoid the following:

  • Providing the cells with a reference to the parent table.
  • Overriding methods in the UITableViewController class to let the cells know whether they are being edited individually or the entire table is editing.

Answers


You can override willTransitionToState: in your UITableViewCell subclass. When the "Edit" button is pressed the state will be UITableViewCellStateShowingEditControlMask(=1) and when swiping it will be UITableViewCellStateShowingDeleteConfirmationMask(=2).


Need Your Help

Understanding reference counting with Cocoa and Objective-C

iphone objective-c cocoa memory

I'm just beginning to have a look at Objective-C and Cocoa with a view to playing with the iPhone SDK. I'm reasonably comfortable with C's malloc and free concept, but Cocoa's references counting s...

Display an image alt or title below the image and in h1 html tag

php jquery html image magento

I've got an image carousel in a site. I want to display the image alt tag or title below the image when I do mover over. At the same time I want to display that same name in another h1 tag.