views:

1814

answers:

3

Hi,

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!

A: 

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.

Roger Nolan
A: 

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 and this sample for help on doing that.

Nick Veys
+1  A: 

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.

Daniel Dickison