开发者

How can I add an "add contact" button like the Contacts application?

How can I add to my app that little "p开发者_运维知识库lus" button that the Contacts application has in the upper right hand corner of the window?

I would like to be able to hit that button and bring up a screen to add a new entry to the table view.


What you're talking about is a UIBarButtonItem.

Here's an example of how to set one up in code:

UIBarButtonItem * addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showContactView:)];
[self.navigationItem setRightBarButtonItem:addButton];
[addButton release];

When tapped, the button will call the follow selector.

- (void)showContactView:(id)sender {
    // Show new contact view.
}


Tom Irving is completely right. It is a UIBarButton and you can configure as he has said. It can be added to a UINavigationBar or UIToolbar as per your requirement.

Hope this helps.

Also dont forget to release this button because some times it causes a crash if you dont release the button instance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜