UIActionSheet与swift
问题描述:
我创建了一个操作表,但问题是没有调用委托方法
I created an action sheet, but the problem is that the delegate method is not called
myActionSheet = UIActionSheet()
myActionSheet.addButtonWithTitle("Add event")
myActionSheet.addButtonWithTitle("close")
myActionSheet.cancelButtonIndex = 1
myActionSheet.showInView(self.view)
/// UIActionSheetDelegate
/// UIActionSheetDelegate
func actionSheet(myActionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
if(myActionSheet.tag == 1){
if (buttonIndex == 0){
println("the index is 0")
}
}
}
我使用了另一种适用于iOS 8的方法但不适用于iOS 7:
I used another way which worked good with iOS 8 but did not work with 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)
有任何解决问题的想法吗?
Any idea to solve the problem?
答
您永远不会设置操作表的委托:
You never set the action sheet's delegate:
myActionSheet = UIActionSheet()
myActionSheet.delegate = self