gpt4 book ai didi

ios7 - UIActionSheet 与 swift

转载 作者:IT王子 更新时间:2023-10-29 05:32:27 33 4
gpt4 key购买 nike

我创建了一个action sheet,但问题是委托(delegate)方法没有被调用

 myActionSheet = UIActionSheet()
myActionSheet.addButtonWithTitle("Add event")
myActionSheet.addButtonWithTitle("close")
myActionSheet.cancelButtonIndex = 1
myActionSheet.showInView(self.view)

///UIActionSheetDelegate

func actionSheet(myActionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
if(myActionSheet.tag == 1){

if (buttonIndex == 0){
println("the index is 0")
}
}
}

我使用了另一种适用于 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)

有解决问题的办法吗?

最佳答案

快速语言的 UIActionSheet :-

带有 cancelButton 和 destructiveButton 的操作表

设置 UIActionSheetDelegate。

        let actionSheet = UIActionSheet(title: "ActionSheet", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Done")
actionSheet.showInView(self.view)

带有 cancelButton 、 destructiveButton 和 otherButton 的操作表

        let actionSheet = UIActionSheet(title: "ActionSheet", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Done", otherButtonTitles: "Yes", "No")
actionSheet.showInView(self.view)

创建操作表函数

func actionSheet(actionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int)
{
switch buttonIndex{

case 0:
NSLog("Done");
break;
case 1:
NSLog("Cancel");
break;
case 2:
NSLog("Yes");
break;
case 3:
NSLog("No");
break;
default:
NSLog("Default");
break;
//Some code here..

}

关于ios7 - UIActionSheet 与 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24172605/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com