【发布时间】:2018-12-07 02:47:08
【问题描述】:
我将使用几个不同的 uibuttons 和 segues 从一个控制器到另一个控制器。我想根据所使用的 segue 将我的分段控件设置为从指定的索引开始。我尝试了下面的代码,但在运行应用程序时收到错误。
代码:
if segue.identifier == "watchedSegue" {
if let detailView = segue.destination as? ListView {
detailView.watchList = watchList
detailView.watchedList = watchedList
detailView.listSeg.selectedSegmentIndex = 1 //Error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
}
}
为什么我在运行应用程序时收到此错误消息?基于segue设置默认索引的首选方式是什么?
【问题讨论】:
-
您可以将选定的索引值分配给目标文件夹中声明的 int 属性,以准备 segue,因为该点的段为 nil,然后您可以在 viewwillApear 方法中将该值分配给段
标签: ios swift segue uisegmentedcontrol