Swift - 操作表(UIActionSheet)的用法,也叫底部警告框
作者:hangge | 2015-01-16 16:27
(注:自IOS8起,建议使用UIAlertController代替UIActionSheet。点击查看UIAlertController的用法)
1,下面创建一个操作表(或叫底部警告框)并弹出显示
2,在一般情况下,工具条,或标签条中显示的调用方式是不一样的
1,下面创建一个操作表(或叫底部警告框)并弹出显示
import UIKit
class ViewController: UIViewController,UIActionSheetDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let actionSheet=UIActionSheet()
//actionSheet.title = "请选择操作"
actionSheet.addButtonWithTitle("取消")
actionSheet.addButtonWithTitle("动作1")
actionSheet.addButtonWithTitle("动作2")
actionSheet.cancelButtonIndex=0
actionSheet.delegate=self
actionSheet.showInView(self.view);
}
func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {
print("点击了:"+actionSheet.buttonTitleAtIndex(buttonIndex)!)
}
}
actionSheet.showInView(self.view); //一般情况 actionSheet.showFromToolbar(self.navigationController.toolbar) //工具条的情况下 actionSheet.showFromTabBar(self.tabBar) //标签条的情况下
全部评论(2)
UIActionSheet 名字也写错了
站长回复:多谢提醒,现已修正。
博主,UIActionSheet 和 UIAlertView 在 iOS 8中已被弃用了,官方建议使用 UIAlertController 来实现 Alert 和 ActionSheet
站长回复:多谢提醒,这篇文章写的比较早,我会在文章中标注下建议改用UIAlertController实现(UIAlertController我也写过相关文章:http://www.hangge.com/blog/cache/detail_651.html)