如何在页面已加载后,如何在uitextfied中设置值

发布于 2025-01-17 10:48:14 字数 271 浏览 3 评论 0原文

我有一个本机iOS项目,我们在其中整合了React Native。在这里,我们有一个本机iOS(Swift)和屏幕B中的屏幕A中的反应本地。 当用户在屏幕中时,单击组件并导航到屏幕B。在屏幕B中,用户选择一个选项并将该值传递给使用NativeModules之间的两个部分之间的brigde。 在该屏幕B被解散之后,用户再次能够看到屏幕A。可以在屏幕上的函数中访问通过桥梁的值,但是当试图将该值设置为UITEXTFIELD获取错误时 :在隐式解开可选值时,意外发现了nil

线程1:致命错误

I have a native iOS project in which we have integrated react native. Here we have a screen A in native iOS(swift) and screen B in React-native.
When user is in screen A clicks on component and navigated to screen B. Inside screen B then user selects a option and passes that value to brigde between the two parts using NativeModules.
After that screen B gets dismissed and user is again able to see the screen A. The value which is passed through bridge can be accessed inside a function in screen A view controller, but when trying to set that value to UITextField getting error Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Expecting to set the value which is received from screen B in screen A gets saved in UITextField to be utilised further

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御弟哥哥 2025-01-24 10:48:14
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

这意味着您尝试使用零的对象。
例如,您有一个TextField对象(Uitextfield的类型),并且您尝试使用:

textField!.text = "Some text"

尚未初始化Textfield。没有代码,很难说出什么问题,但是要么您之前应该在某个地方进行过启动文本字段:

textField = UITextField()

或者您应该安全地解开字段,然后尝试设置该值 - 如果零,则仍然不会设置它。

textField?.text = "Some text"
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

This means that you tried to use an object which is nil.
E.g. you had a textField object (type of UITextField) and you tried to use:

textField!.text = "Some text"

Your textField is not yet initialized. Without code it's hard to say what's wrong but either you should have initilaized textField somewhere before:

textField = UITextField()

Or you should safely unwrap the field and try to set the value - if it's nil it still won't be set.

textField?.text = "Some text"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文