gpt4 book ai didi

ios - 使用不同的 ActionSheets Swift

转载 作者:行者123 更新时间:2023-11-29 02:39:56 26 4
gpt4 key购买 nike

我目前尝试使用 2 个操作表(或可能更多)并希望对它们进行不同的操作。

 @IBAction func BTActionSheet(sender: AnyObject) {

let action:UIActionSheet = UIActionSheet(title: "Change Map Type", delegate: self, cancelButtonTitle: "Back", destructiveButtonTitle: nil, otherButtonTitles: "Satelite", "Normal","Hybride")
action.showInView(self.view)
}

这是我用于更改 MapType 的 ActionSheet

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

println(buttonIndex)
if buttonIndex == 1{ Map.mapType = MKMapType.Satellite }
if buttonIndex == 2{ Map.mapType = MKMapType.Standard }
if buttonIndex == 3{ Map.mapType = MKMapType.Hybrid }
}

所以想添加一个 2.ActionSheet 做类似的事情

 @IBAction func BTActionSheet1(sender: AnyObject) {

let action1:UIActionSheet = UIActionSheet(title: "secound", delegate: self, cancelButtonTitle: "Back", destructiveButtonTitle: nil, otherButtonTitles: "one", "two")
action.showInView(self.view)
}

并使用这个

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

println(buttonIndex)
if buttonIndex == 1{ println("otheone") }
if buttonIndex == 2{ println("otheone2") }
}

如何检查我的 buttonIndex 来自哪个 ActionSheet?

最佳答案

您可以使用 UIActionSheet(继承自 UIView)tag属性:

 @IBAction func BTActionSheet(sender: AnyObject) {

let action:UIActionSheet = UIActionSheet(title: "Change Map Type", delegate: self, cancelButtonTitle: "Back", destructiveButtonTitle: nil, otherButtonTitles: "Satelite", "Normal","Hybride")
action.tag = 1
action.showInView(self.view)
}

@IBAction func BTActionSheet1(sender: AnyObject) {

let action1:UIActionSheet = UIActionSheet(title: "secound", delegate: self, cancelButtonTitle: "Back", destructiveButtonTitle: nil, otherButtonTitles: "one", "two")
action1.tag = 2
action1.showInView(self.view)
}

func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int){
if actionSheet.tag == 1
{
println(buttonIndex)
if buttonIndex == 1{ Map.mapType = MKMapType.Satellite }
if buttonIndex == 2{ Map.mapType = MKMapType.Standard }
if buttonIndex == 3{ Map.mapType = MKMapType.Hybrid }
}
if actionSheet.tag == 2
{
println(buttonIndex)
if buttonIndex == 1{ println("otheone") }
if buttonIndex == 2{ println("otheone2") }
}
}

关于ios - 使用不同的 ActionSheets Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25914185/

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