尝试设置文本字段占位符,段uiview时出现nil错误

时间:2018-11-04 02:22:44

标签: swift xcode uitextfield uisegmentedcontrol uiview-hierarchy

xcode v:9.2

我正在尝试从数据库中加载用户信息以设置为占位符文本。我已经在一个没有段视图的简单项目中测试了此代码,并且工作正常。我做了一些研究,我认为这可能是一个分层的问题。我努力了解如何加载文本字段值,以便在我尝试访问它们并设置占位符值时将它们指向的位置连接起来。

GetCurr retrieves database values and sends them to completion handler function to write placeholder value. When run, "setPH = nil"

Calls GetCurr for email

Completion handler that sets placeholder text

loadUserView should tell when to load the values of this particular segment

I know it's not my IBOutlets because they are all connected and as previously said, this code works perfectly fine in a simpler app that does not have segment views.

1 个答案:

答案 0 :(得分:0)

我知道了!我将这些段连接到具有自己的uiviewcontroller类的uiview,作为父基类的子类。这也使我的代码更干净,更漂亮!

有用: https://docs.swift.org/swift-book/LanguageGuide/Inheritance.html https://cocoacasts.com/managing-view-controllers-with-container-view-controllers/