开发者

How to make UIBarButtonItem give menu-options?

开发者 https://www.devze.com 2023-01-07 05:48 出处:网络
You know how if you click and hold on a link in Safari (for iPhone obviously) it gives you a list of options like "open in new window", "Open". "Copy" etc?

You know how if you click and hold on a link in Safari (for iPhone obviously) it gives you a list of options like "open in new window", "Open". "Copy" etc?

How do you call this and is it possible to get a UIBarButt开发者_开发知识库onItem to do this (but every time it is clicked not just when held down)?


This is how you show this menu:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                         delegate:self 
                                                cancelButtonTitle:@"Cancel", 
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:@"Button 1", @"Button 2", @"Button 3", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

[actionSheet showInView:[self view]];
[actionSheet release];

In order to connect it to UIBarButtonItem just point the bar button item to a selector that will include the code above.

Don't forget to implement - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex method of UIActionSheetDelegate.

0

精彩评论

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

关注公众号