我创建了一个操作表,但问题是没有调用委托方法
myActionSheet = UIActionSheet()
myActionSheet.addButtonWithTitle("Add event")
myActionSheet.addButtonWithTitle("close")
myActionSheet.cancelButtonIndex = 1
myActionSheet.showInView(self.view)
Run Code Online (Sandbox Code Playgroud)
/// UIActionSheetDelegate
func actionSheet(myActionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
if(myActionSheet.tag == 1){
if (buttonIndex == 0){
println("the index is 0")
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用了另一种适用于iOS 8的方法但不适用于iOS 7:
var ActionSheet = UIAlertController(title: "Add View", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)
ActionSheet.addAction(UIAlertAction(title: "Add event", style: UIAlertActionStyle.Default, handler:nil))
self.presentViewController(ActionSheet, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
有什么想法解决这个问题吗?