【发布时间】:2018-02-22 03:31:49
【问题描述】:
我使用 xCode 8 创建了两个 TableViewController。我正在尝试将数据从一个 TableViewController 中的选定单元格传递到第二个。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let currentCell = tableView.cellForRow(at: indexPath) as! WorkOutCell
let workout = WorkOut()
selectedWorkout = workout.getWorkOutByName(workoutName: currentCell.workoutNameLabel.text!)
let evc = ExerciseViewController(nibName: "ExerciseViewController", bundle: nil)
evc.selectedWorkout = selectedWorkout //sets the selected workout value in ExerciseViewControler
print(evc.nibName as Any) //prints Optional("ExerciseViewController")
present(evc, animated: true, completion: nil) //throws exception
}
当我对此进行调试时,数据被传递给了 ExerciseViewController,这样似乎就可以工作了。打印行选择了 ExerciseViewController 作为 nibName,但是在 present 方法上抛出了一个异常,它找不到 ExerciseViewController 的 nibName。
2018-02-21 06:00:43.786 每月 HIIT[1994:132476] *** 终止应用 由于未捕获的异常“NSInternalInconsistencyException”,原因: '无法在包中加载NIB:'NSBundle (已加载)',名称为 'ExerciseViewController''
我对这个问题感到困惑。我将文件添加到构建路径,但没有奏效。其他问题建议添加 XIB 文件,但通过挖掘 XIB 文件似乎与我创建的故事板无关(尽管我很容易出错)。非常感谢任何帮助或建议。
谢谢
【问题讨论】:
-
让 storyboard = UIStoryboard(name: "Storyboard Name", bundle: nil);让 viewController = storyboard.instantiateViewController(withIdentifier: "Storyboard ID") as! UINavigationController;self.present(viewController, animated:true, completion: nil)
-
感谢@michael-dautermann 和 El Tomato,这是我缺少的部分。非常感谢您的 cmets 帮助解决这个问题。
-
@D.Charlton 如果下面迈克尔的回答解决了您的问题,您应该通过单击答案左侧的复选标记来表明这一点。