Frank C
Frank C

Reputation:

UITableView: moving a row into an empty section

I have a UITableView with some empty sections. I'd like the user to be able to move a row into them using the standard edit mode controls. The only way I can do it so far is to have a dummy row in my "empty" sections and try to hide it by using tableView:heightForRowAtIndexPath: to give the dummy row a height of zero. This seems to leave it as a 1-pixel row. I can probably hide this by making a special type of cell that's just filled with [UIColor groupTableViewBackgroundColor], but is there a better way?

This is all in the grouped mode of UITableView.

UPDATE: Looks like moving rows into empty sections is possible without any tricks, but the "sensitivity" is bad enough that you DO need tricks in order to make it usable for general users (who won't be patient enough to slowly hover the row around the empty section until things click).

Upvotes: 5

Views: 3005

Answers (3)

arlomedia
arlomedia

Reputation: 9061

I found that in iOS 4.3, the dummy row needs to have a height of at least 1 pixel in order to give the desired effect of allowing a row to be moved into that section.

I also found that the dummy row is only needed in the first and last section; any sections in between don't have this problem.

And it looks like in iOS 5.0, no dummy rows or special tricks are needed at all.

Upvotes: 1

Zac
Zac

Reputation: 323

I found that if you return -1.0 from the heightForRowAtIndexPath method it will remove the 1 pixel line.

Upvotes: 0

slf
slf

Reputation: 22767

While managing the edit, you can monitor if the table view is in Edit Mode. Use that flag inside of cellForRowAtIndexPath to decide weather or not to display the 'blank' row. While in 'regular' mode, the row will not display, but when the user taps 'edit' cellForRowAtIndexPath should get called again and this time decide to display the row. The details of how to do that depend on your data source and how you are gluing it to the display. If you aren't getting the call again, you can manually inject rows with insertRowsAtIndexPaths / deleteRowsAtIndexPaths and/or call reloadData to force a refresh.

Upvotes: 0

Related Questions