如何用UIActionSheet传递参数?

时间:2021-04-02 20:14:10

I have an Action Sheet popping up and I want to pass a certain argument to a button processing method.

我弹出一个Action Sheet,我想将一个参数传递给一个按钮处理方法。

For example:

I have a table and I want to pass to a button processing method row number that was selected in a table.

我有一个表,我想传递给在表中选择的按钮处理方法行号。

How can I achieve this?

我怎样才能做到这一点?

4 个解决方案

#1


6  

You would have to set this in your delegate ahead of time. You can then use this value when your delegate receives the button press notification.

您必须提前在委托中设置此项。然后,当您的代理人收到按钮通知时,您可以使用此值。

#2


3  

If it is an integer argument, put it as the tag property of the action sheet. Otherwise, you can subclass the action sheet and put variables there, or use associative references.

如果是整数参数,则将其作为操作表的tag属性。否则,您可以对操作表进行子类化并将变量放在那里,或使用关联引用。

#3


3  

if you want to pass an integer, use UIActionSheet.tag. if you want to pass a NSString, use UIActionSheet.accessibilityValue.

如果要传递整数,请使用UIActionSheet.tag。如果要传递NSString,请使用UIActionSheet.accessibilityValue。

these are simple and easy. no need to create an instance variable.

这些简单易行。无需创建实例变量。

#4


-1  

swift 1.2 code :

swift 1.2代码:

in your method :

在你的方法中:

let item1 = “item1”
let item2 = “item2”
let actionSheet = UIActionSheet(title: “Title ",
                                delegate: self, 
                                cancelButtonTitle: "Cancel", 
                                destructiveButtonTitle: “Here”,
                                otherButtonTitles: “There”)

     actionSheet.accessibilityElements = [item1, item2]

in that function

在那个功能

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

let item1 = actionSheet[0]
let item2 = actionSheet[1]

}

#1


6  

You would have to set this in your delegate ahead of time. You can then use this value when your delegate receives the button press notification.

您必须提前在委托中设置此项。然后,当您的代理人收到按钮通知时,您可以使用此值。

#2


3  

If it is an integer argument, put it as the tag property of the action sheet. Otherwise, you can subclass the action sheet and put variables there, or use associative references.

如果是整数参数,则将其作为操作表的tag属性。否则,您可以对操作表进行子类化并将变量放在那里,或使用关联引用。

#3


3  

if you want to pass an integer, use UIActionSheet.tag. if you want to pass a NSString, use UIActionSheet.accessibilityValue.

如果要传递整数,请使用UIActionSheet.tag。如果要传递NSString,请使用UIActionSheet.accessibilityValue。

these are simple and easy. no need to create an instance variable.

这些简单易行。无需创建实例变量。

#4


-1  

swift 1.2 code :

swift 1.2代码:

in your method :

在你的方法中:

let item1 = “item1”
let item2 = “item2”
let actionSheet = UIActionSheet(title: “Title ",
                                delegate: self, 
                                cancelButtonTitle: "Cancel", 
                                destructiveButtonTitle: “Here”,
                                otherButtonTitles: “There”)

     actionSheet.accessibilityElements = [item1, item2]

in that function

在那个功能

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

let item1 = actionSheet[0]
let item2 = actionSheet[1]

}