开发者

Customizing UINavigationController's Edit button?

开发者_如何转开发How do I draw "save" & "cancel" buttons on the navigation bar when the user taps "edit"? Also, how do I hide the delete "knobs" and instead make each row editable, like Apple's Contacts app?


An UIViewController has a -setEditing:animated: method that you can overwrite. In this method you could call -setRightBarButtonItem or -setLeftBarButtonItem.

As for your second question, take a look at the UITableViewDataSource. There's a method called -tableView:moveRowAtIndexPath:toIndexPath.

EDIT: If you want to enter text in a UITableViewCell, you have to place a UITextField inside it in your -tableView:cellForRowAtIndexPath:. Look here.


To create a Cancel button on the left side, implement the setEditing:animated: method and put the following inside.

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelEdit:)] autorelease];

And to add a Save button:

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(SaveEdit:)] autorelease];

Make sure you implement cancelEdit: and saveEdit:.


To both answers, I should add the following:

To remove added button, set the right/leftBarButtonItem to nil

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜