有没有办法用sdk轻松实现这个菜单,还是我必须手动制作(将叠加视图和其他视图与按钮组合在一起)?
提前致谢!
答案 0 :(得分:4)
这是来自标准UIKit框架的UIActionSheet类
答案 1 :(得分:0)
来自UIActionSheet
的{{3}}的简单示例让我有点扩展来解除呼叫操作。
DelCon在ViewController的全球范围内:
UIActionSheet * actionSheet;
和UIView * yourView;
在viewDidLoad中:
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Delete Note"
otherButtonTitles:@"Call",@"Add a Contact",nil];
[yourView = self.view]
要通过IBAction的某个声明按钮触发菜单,您需要:
-(IBAction)viewMapButton:(id) sender
{
[actionSheet showInView:yourView];
}
根据用户选择采取适当的行动,声明以下方法并检查[actionSheet buttonTitleAtIndex:buttonIndex]
等于:
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString * what_action = [actionSheet buttonTitleAtIndex:buttonIndex];
NSLog(@"The %@ button was tapped.", what_action);
if ([what_action isEqualToString:@"Call"])
{
NSString *phoneNumber = [[NSString alloc]
initWithString:@"telprompt:1234567890"];
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:phoneNumber]];
}
}
[注意:拨打电话不适用于iOS模拟器]