Xcode 11.1 中的警报对话框错误?
Alert dialog bug in Xcode 11.1?
我昨天决定将 Xcode 更新到版本 11.1 (11A1027),我想我要么发现了一个错误,要么 Swift 语法发生了变化。
我有一个几乎空白的 viewController,它有两个按钮,一个关闭 ViewController,另一个显示警报。
@IBAction func search_BTN(_ sender: Any) {
//1. Create the alert controller.
let alert = UIAlertController(title: "Some Title", message: "Enter a text", preferredStyle: .alert)
//2. Add the text field. You can configure it however you need.
alert.addTextField { (textField) in
textField.text = "Some default text"
}
// 3. Grab the value from the text field, and print it when the user clicks OK.
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak alert] (_) in
let textField = alert?.textFields![0] // Force unwrapping because we know it exists.
print("Text field: \(textField?.text)")
}))
// 4. Present the alert.
self.present(alert, animated: true, completion: nil)
}
如果删除 addTextField
代码,警报将 仅 显示。否则应用程序会冻结,我必须强行关闭它。我认为正在发生的事情是显示空白对话框或程序陷入循环。我认为这是因为应用程序不会崩溃并且我没有收到任何错误消息。我唯一得到的就是这个,
XPC connection interrupted
据我所知,这意味着应用程序超时。
我试过的
- 其他视图控制器(遇到同样的问题)
- 另一个 Xcode 项目(遇到同样的问题)
- Xcode 10(有效)
- 正在清理项目
什么我还没腻
- 物理 iOS 设备(只是模拟器)
- 另一台使用最新版本 Xcode
的计算机
谁能确认这个错误?有谁知道这个问题的解决方法?或者是否有另一种方法可以在不安装 Pods 的情况下使用文本字段显示警报(我喜欢尽可能多地使用第一方代码)。
EDIT1:我认为这可能只是一般的文本字段。我厌倦了通过在视图控制器中使用文本字段来解决这个问题,但我仍然遇到同样的问题。我也厌倦了清理项目和重建。同样的事情发生了。可能会卸载并重新安装 Xcode。如果这不起作用,我可能不得不尝试安装测试版。
EDIT2:我有一个疯狂的想法要做一些完全有意义的事情。我将 OS 更新为 Catalina 并解决了问题。如果有人知道为什么会这样,我会很想知道的。假设这与某种缓存有关。
我最近遇到了类似的问题,显然这是 Apple 确认的错误:https://forums.developer.apple.com/thread/122972
有一个解决方法是在模拟器上禁用粘贴板同步。
取消选中编辑 -> 自动同步粘贴板中的选项
重启模拟器。
我昨天决定将 Xcode 更新到版本 11.1 (11A1027),我想我要么发现了一个错误,要么 Swift 语法发生了变化。
我有一个几乎空白的 viewController,它有两个按钮,一个关闭 ViewController,另一个显示警报。
@IBAction func search_BTN(_ sender: Any) {
//1. Create the alert controller.
let alert = UIAlertController(title: "Some Title", message: "Enter a text", preferredStyle: .alert)
//2. Add the text field. You can configure it however you need.
alert.addTextField { (textField) in
textField.text = "Some default text"
}
// 3. Grab the value from the text field, and print it when the user clicks OK.
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak alert] (_) in
let textField = alert?.textFields![0] // Force unwrapping because we know it exists.
print("Text field: \(textField?.text)")
}))
// 4. Present the alert.
self.present(alert, animated: true, completion: nil)
}
如果删除 addTextField
代码,警报将 仅 显示。否则应用程序会冻结,我必须强行关闭它。我认为正在发生的事情是显示空白对话框或程序陷入循环。我认为这是因为应用程序不会崩溃并且我没有收到任何错误消息。我唯一得到的就是这个,
XPC connection interrupted
据我所知,这意味着应用程序超时。
我试过的
- 其他视图控制器(遇到同样的问题)
- 另一个 Xcode 项目(遇到同样的问题)
- Xcode 10(有效)
- 正在清理项目
什么我还没腻
- 物理 iOS 设备(只是模拟器)
- 另一台使用最新版本 Xcode 的计算机
谁能确认这个错误?有谁知道这个问题的解决方法?或者是否有另一种方法可以在不安装 Pods 的情况下使用文本字段显示警报(我喜欢尽可能多地使用第一方代码)。
EDIT1:我认为这可能只是一般的文本字段。我厌倦了通过在视图控制器中使用文本字段来解决这个问题,但我仍然遇到同样的问题。我也厌倦了清理项目和重建。同样的事情发生了。可能会卸载并重新安装 Xcode。如果这不起作用,我可能不得不尝试安装测试版。
EDIT2:我有一个疯狂的想法要做一些完全有意义的事情。我将 OS 更新为 Catalina 并解决了问题。如果有人知道为什么会这样,我会很想知道的。假设这与某种缓存有关。
我最近遇到了类似的问题,显然这是 Apple 确认的错误:https://forums.developer.apple.com/thread/122972
有一个解决方法是在模拟器上禁用粘贴板同步。
取消选中编辑 -> 自动同步粘贴板中的选项
重启模拟器。