当您想要回复邮件时,我想创建一个类似于邮件应用程序中的弹出菜单。我已经在多个应用程序中看到过这个,所以我不确定框架中是否有内置的东西或者那些示例代码。
答案 0 :(得分:22)
代码已更新为Swift 3
自iOS 8起,SELECT ProcName = COALESCE(OBJECT_NAME(St.objectid), 'Ad-Hoc'),
ParentQueryText = St.Text,
IndividualStatementText = SUBSTRING(St.text, (Qs.statement_start_offset / 2) + 1, ((CASE Qs.statement_end_offset
WHEN -1 THEN DATALENGTH(St.text)
ELSE Qs.statement_end_offset
END - Qs.statement_start_offset) / 2) + 1),
LastTimeRun = Qs.last_execution_time
FROM sys.dm_exec_query_stats AS Qs
CROSS APPLY sys.Dm_exec_sql_text(Qs.sql_handle) AS St
与UIAlertController
结合使用。 {@ 1}}已被弃用。
以下是在上图中生成操作表的代码:
UIAlertControllerStyle.ActionSheet
还需要帮助吗?观看此视频教程。这就是我学习它的方式。
UIActionSheet
操作表而不是class ViewController: UIViewController {
@IBOutlet weak var showActionSheetButton: UIButton!
@IBAction func showActionSheetButtonTapped(sender: UIButton) {
// Create the action sheet
let myActionSheet = UIAlertController(title: "Color", message: "What color would you like?", preferredStyle: UIAlertControllerStyle.actionSheet)
// blue action button
let blueAction = UIAlertAction(title: "Blue", style: UIAlertActionStyle.default) { (action) in
print("Blue action button tapped")
}
// red action button
let redAction = UIAlertAction(title: "Red", style: UIAlertActionStyle.default) { (action) in
print("Red action button tapped")
}
// yellow action button
let yellowAction = UIAlertAction(title: "Yellow", style: UIAlertActionStyle.default) { (action) in
print("Yellow action button tapped")
}
// cancel action button
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { (action) in
print("Cancel action button tapped")
}
// add action buttons to action sheet
myActionSheet.addAction(blueAction)
myActionSheet.addAction(redAction)
myActionSheet.addAction(yellowAction)
myActionSheet.addAction(cancelAction)
// support iPads (popover view)
myActionSheet.popoverPresentationController?.sourceView = self.showActionSheetButton
myActionSheet.popoverPresentationController?.sourceRect = self.showActionSheetButton.bounds
// present the action sheet
self.present(myActionSheet, animated: true, completion: nil)
}
}
。)答案 1 :(得分:20)
iOS 8+上为UIAlertController
,早期版本为UIActionSheet
。
答案 2 :(得分:14)
查看Apple网站上的UICatalog示例。 “警报”部分提供了如何使用UIActionSheet来完成您要执行的操作的示例。
答案 3 :(得分:9)
您需要使用UIActionSheet。
首先,您需要将UIActionSheetDelegate添加到ViewController .h文件中。
然后您可以使用以下内容引用操作表:
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
@"Share on Facebook",
@"Share on Twitter",
@"Share via E-mail",
@"Save to Camera Roll",
@"Rate this App",
nil];
popup.tag = 1;
[popup showInView:self.view];
然后你必须处理每个电话。
- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (popup.tag) {
case 1: {
switch (buttonIndex) {
case 0:
[self FBShare];
break;
case 1:
[self TwitterShare];
break;
case 2:
[self emailContent];
break;
case 3:
[self saveContent];
break;
case 4:
[self rateAppYes];
break;
default:
break;
}
break;
}
default:
break;
}
}
自iOS 8.x起已被弃用。
答案 4 :(得分:5)
这就是你在iOS 8 +上的Objective-C中的表现:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Directions"
message:@"Select mode of transportation:"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *drivingAction = [UIAlertAction actionWithTitle:@"Driving" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// this block runs when the driving option is selected
}];
UIAlertAction *walkingAction = [UIAlertAction actionWithTitle:@"Walking" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// this block runs when the walking option is selected
}];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:drivingAction];
[alert addAction:walkingAction];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
答案 5 :(得分:2)
对于在Swift中寻找解决方案的每个人:
采用UIActionSheetDelegate
协议
创建并显示ActinSheet:
let sheet: UIActionSheet = UIActionSheet()
sheet.addButtonWithTitle("button 1")
sheet.addButtonWithTitle("button 2")
sheet.addButtonWithTitle("button 3")
sheet.addButtonWithTitle("Cancel")
sheet.cancelButtonIndex = sheet.numberOfButtons - 1
sheet.delegate = self
sheet.showInView(self.view)
委托功能:
func actionSheet(actionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
switch buttonIndex{
case 0:
NSLog("button1");
case 1:
NSLog("button2");
case 2:
NSLog("button3");
case actionSheet.cancelButtonIndex:
NSLog("cancel");
break;
default:
NSLog("blub");
break;
}
}
答案 6 :(得分:0)
我尝试在我的视图中添加ActionSheet。所以我一直试图找到完美的解决方案,但一些答案让我感到困惑。因为关于行动表的大多数问题都是在很久以前写的。它还没有更新。 无论如何......我将编写旧版ActionSheet和更新版本的ActionSheet。 我希望我的回答能让你的大脑和平。
----------更新版本---------
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"Action Sheet" message:@"writeMessageOrsetAsNil" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* actionSheet01 = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) { NSLog(@"OK click");}];
UIAlertAction* actionSheet02 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {NSLog(@"OK click");}];
UIAlertAction* actionSheet03 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
NSLog(@"Cancel click");}];
[browserAlertController addAction:actionSheet01];
[browserAlertController addAction:actionSheet02];
[browserAlertController addAction:actionSheet03];
[self presentViewController:browserAlertController animated:YES completion:nil];
-------旧版------
UIActionSheet *actionSheet= [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@“OK”, @“NO”,@“Cancel”,
nil];
actionSheet.tag = 100;
[actionSheet showInView:self.view];
- (void)actionSheet:(UIActionSheet *)actionShee clickedButtonAtIndex:(NSInteger)buttonIndex {
if( actionSheet.tag == 100){
switch (buttonIndex) {
case 0:
[self doSomething];
break;
case 1:
[self doAnything];
break;
case 2:
[self doNothing];
break;
default:
break;
}
break;
}
}