While trying to change placeholder text, fatal error: unexpectedly found nil while unwrapping an Optional value

While trying to change placeholder text, fatal error: unexpectedly found nil while unwrapping an Optional value

我正在尝试修改 Swift 中文本字段的占位符文本。但是关于 "fatal error: unexpectedly found nil while unwrapping an Optional value." 有一个错误,我不确定为什么这会是零。

谢谢!

inputUITextField!。它可能是 nil,这可能意味着您忘记在 Interface Builder 中连接它。

因为你有弱指针,我认为你应该使用 ? 并再次使用它来解包你的变量。

@IBOutlet weak var input: UITextField?

input?.placeholder = "some text";

但是正如有人所说,您可能还没有连接 IBOutlet。