gpt4 book ai didi

swift - UIAlertView clickedButtonAtIndex

转载 作者:行者123 更新时间:2023-11-28 09:59:20 25 4
gpt4 key购买 nike

我正在实现一个 UIAlertView,需要它在 iOS7 上运行。下面的代码有效,但我的问题是关于 alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) 函数的行为。

我有一个 println("button index clicked (buttonIndex)") 我用来打印哪个按钮被点击了。按钮工作正常,打印 0 和 1。

而且当 alertView 启动时,我打印了一个 0。这应该如何工作?还是这里有问题?

UPDATED CODE

        @IBAction func purgeDatabase() {

// fetch request
let fetchRequest = NSFetchRequest(entityName: "ConcreteBagEntity")
var error : NSError?

// execute fetch request
if let fetchResults = self.managedObjectContext!.executeFetchRequest(fetchRequest, error: &error) as? [ConcreteBagEntity] {
if error != nil{
return
}

// if results are found
if fetchResults.count != 0 {

let purgeAlertController = UIAlertView(title: "Before you go ahead", message: "You are about to delete all your previous quotes. Are you sure you want to go ahead?", delegate: self, cancelButtonTitle: "Cancel")
purgeAlertController.addButtonWithTitle("Ok")
purgeAlertController.show()

}// END IF FETCH != 0
else{
alertViewLaunch("Looks like there is nothing here to delete")
}
}//END FETCH REQUEST
}//END IBACTION

func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
println("button index clicked -> \(buttonIndex)")
if buttonIndex == 1 {
purgeAllData()
}
}

最佳答案

您在以下行中自己调用了它:

self.alertView(purgeAlertController, clickedButtonAtIndex: Int())

相反,您可以调用 here

关于swift - UIAlertView clickedButtonAtIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31695735/

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