views:

68

answers:

2

A good example of the behavior I'm trying to illustrate is when you click on the "Edit" button in the iOS Clock app, the on/off switch transforms into a chevron.

I have a UITableView that contains a cell with a switch control on it. When the user click the "Edit" button in the nav bar, I'd like the switch to go away and get replaced with a chevron. I'm new to iOS development, so up to this point I really only understand how to change the editing mode of the UITableView and delete cells.

How do I configure a UITableViewCell to hide it's switch control and display the chevron when the user clicks the "Edit" button in the nav bar?

Thanks so much in advance for your help!

+1  A: 

In tableView:cellForRowAtIndexPath: you check if the tableView is in edit mode. If it is in regular mode you set the accessoryView to the switch object. If it's in edit mode you set the accessoryView to nil and the accessoryType to UITableViewCellAccessoryDisclosureIndicator (the "chevron").

RupertP
thank you, kind sir!
BeachRunnerJoe
+1  A: 

It might be better to actually set your cell.editingAccessoryView to your UISwitch object, and just have the cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;. That way, when the user hits the Edit button, your chevron will slide out and your UISwitch will slide in without any additional work on your part.

Joe Ibanez
thanks, that worked much better!
BeachRunnerJoe
You're welcome! I just did something very similar, so it was fresh in my mind.
Joe Ibanez