gpt4 book ai didi

ios - swift 等待用户响应

转载 作者:搜寻专家 更新时间:2023-11-01 06:30:02 24 4
gpt4 key购买 nike

我创建了一个提醒:

var a = 0 // default
let userAction = UIAlertController(title: "Select", message: "Select an action", preferredStyle: UIAlertControllerStyle.alert)

userAction.addAction(UIAlertAction(title: "action 1", style: .default, handler: { (action: UIAlertAction!) in
a = 1
}))

userAction.addAction(UIAlertAction(title: "action 2", style: .cancel, handler: { (action: UIAlertAction!) in
a = 2
}))

present(userAction, animated: true, completion: nil)

let resp = Just.get("http://localhost/\(a)").text
return resp

在这段代码之后,我发送了一个带有参数 (a) 的请求,但请求是在选择操作之前发送的。我怎样才能等到用户选择并从警报中采取行动?

最佳答案

删除 present 调用下方的调用函数。将它移到您的警报按钮操作关闭

var a = 0 // default
let userAction = UIAlertController(title: "Select", message: "Select an
action", preferredStyle: UIAlertControllerStyle.alert)

userAction.addAction(UIAlertAction(title: "action 1", style: .default,
handler: { (action: UIAlertAction!) in
a = 1
// Call function here
}))

userAction.addAction(UIAlertAction(title: "action 2", style: .cancel,
handler: { (action: UIAlertAction!) in
a = 2
// Call function here
}))

present(userAction, animated: true, completion: nil)

关于ios - swift 等待用户响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48659271/

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