views:

77

answers:

3

Hey.

I am using a UItableView to show a list of stuff. When the user clicks on the accessory, it writes the location of the cell to a plist. Then it sends the [UITableView reloadData]-selector to the tableView.

How can I set a different indexPath to a UITableViewCell inside the tableView: cellForRowAtIndexPath: method?

Thank you.

A: 

To display a default clickable accessory button from tableView: cellForRowAtIndexPath: you should set:

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

You will then use tableView:accessoryButtonTappedForRowWithIndexPath: to perform actions after the user taps the button.

prendio2
I want to rearrange the position of a tableviewcell when initialized in the `tableView: cellForRowAtIndexPath:` method.
Emil
this is not possible… see Jasconius's answer
prendio2
+3  A: 

You can't do it inside of that method.

You have to manipulate your datasource and call [tableView reloadData] to reorder.

You can't magically change a cell position within cellForRowAtIndexPath. It's cell. For a row. An an index path.

Jasconius
Thanks ..I'll try to manipulate the datasource ;)
Emil
+1  A: 

Content in the UITableView is really just a reflection of your datasource. Update your datasource, then reload the tableview to reflect this change. If you're having trouble manipulating your datasource read this: https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html

DysonApps
Thanks, but this is already resolved ;)
Emil