gpt4 book ai didi

iphone - 将 TextField 添加到 AlertController 会破坏 AlertController

转载 作者:行者123 更新时间:2023-11-30 11:58:41 26 4
gpt4 key购买 nike

我目前正在尝试打开一个包含 TextField 的 AlertController。运行时

let configAlert = UIAlertController(title: "Configure Add-On", message: "Enter Your Add-On Name:", preferredStyle: UIAlertControllerStyle.alert)

configAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in
// Handle Input
}))

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

一切正常,但是一旦我添加 TextField

configAlert.addTextField { (textField) in
textField.placeholder = "Name"
}

警报需要大约 10 倍的时间才能打开,然后立即关闭,并且我在控制台中收到此错误垃圾邮件大约 30 次:

2017-11-26 13:04:08.985783-0500 MinelyMod[380:14792] Warning: Attempt to dismiss from view controller <UISplitViewController: 0x147e0a6a0> while a presentation or dismiss is in progress!

这是已完成的 AlertController,但失败了

let configAlert = UIAlertController(title: "Configure Add-On", message: "Enter Your Add-On Name:", preferredStyle: UIAlertControllerStyle.alert)

configAlert.addTextField { (textField) in
textField.placeholder = "Name"
}

configAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in
// Handle Input
}))

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

最佳答案

let alertController = UIAlertController(title: "Title", message: "", preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: "Save", style: .default, handler: {
alert -> Void in
let textField = alertController.textFields![0] as UITextField
// do something with textField
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

alertController.addTextField(configurationHandler: {(textField : UITextField!) -> Void in
textField.placeholder = "Search"
})

self.present(alertController, animated: true, completion: nil)

关于iphone - 将 TextField 添加到 AlertController 会破坏 AlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47499359/

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