iPhone app Action Button

2020-04-16 06:05发布

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!

3条回答
可以哭但决不认输i
2楼-- · 2020-04-16 06:25

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2020-04-16 06:33

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.

查看更多
我命由我不由天
4楼-- · 2020-04-16 06:33

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.

查看更多
登录 后发表回答