The iPhone Mail application has an edit button in the navigation bar. Tapping that button shows a delete button in the toolbar and shows checkbox开发者_运维百科 controls in the table cells. Tapping one or more checkboxes then tapping the delete button causes the checked messages to be deleted.
How can I add similar functionality to my own code?
Here's a screenshot of the effect I'm looking for:
screenshot of spam folder with some messages checked http://www.freeimagehosting.net/uploads/add199aa62.png
UINavigationBar has a UINavigationItem with a leftBarButtonItem and a rightBarButtonItem. To set your edit button you init a bar button item with the style: UIBarButtonSystemItemEdit.
Follow the delete button example here: http://dragonforged.com/devblog/?p=34
@DavidSowsy's answer only shows how to draw a red button.
For those actually interested in selecting multiple rows in a UITableView, I have found 2 ways to do it:
The easy way that involves undocumented APIs and will probably make your app crash in the next OS update.
The proper one, that is a bit more work but works well and you won't have to think about it again.
For my project, I chose the latter.
精彩评论