Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用委托方法从当前视图控制器更新我的顶视图控制器中的一些 UI。我收到错误消息unexpectedly found nil while unwrapping an Optional value。请查看以下代码并提出问题所在。
unexpectedly found nil while unwrapping an Optional value
我修好了它。prepareForSegue我在我的第一个视图控制器中缺少实现。
prepareForSegue
我不得不将委托分配给 self in prepareForSegue。我不能这样做
let vc = SecondViewController() vc.sampleProtocol = self
我在我的viewDidLoad()
viewDidLoad()
您不能像在 viewDidLoad 中的代码中那样设置委托。您必须实施 prepareForSegue 并将您的委托设置在那里。