iPhone app Action Button

2020-04-16 05:42发布

问题:

I need to add an action button in my iPhone application. When that one is clicked the UIActionSheet with buttons need to be popped up. Can any one tell me how to add an action button? - means is there any in built action button for iPhone app? or do we need to create a new button with image?

Thanks in advance!

回答1:

Assuming this is in a view controller, you can do something like:

- (void)viewDidLoad
{
    UIBarButtonItem *actionButton = [[UIBarButtonItem alloc]
            initWithBarButtonSystemItem:UIBarButtonSystemItemAction
            target:self
            action:@selector(methodThatShowsSheet)];
    self.navigationItem.rightBarButtonItem = actionButton;
    [actionButton release];
}

(Pardon the weird indentation to make it fit in a reasonable width (I normally just let Xcode wrap-indent everything automatically)).

See Nick Veys' answer for how to implement methodThatShowsSheet.



回答2:

You need to hook up the action from the button you've decided will present this action sheet to code that shows it.

See the Apple Documentation on UIActionSheet for help on doing that.



回答3:

I'm not sure I understnd your question but UIKit includes the UIButton class which will automatically send a message (specified by you) to an object (also specified by you). You can create a UIButton i nInterface builder or programatically.

Without more details on whay you actually want to do or why you're finding it difficult,m it's difficult to be more precise.