从故事板中选择您的视图控制器并选择身份检查器给故事板ID任何你想要的
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"your storyboard name" bundle:nil];
MyNewViewController *myVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:@"your storyboard id"];
我在这里下载了示例https://www.raywenderlich.com/115697/ios-9-storyboards-tutorial-whats-new-in-storyboards
他们使用故事板参考作为segue。在这里我修改了以下内容:
1.select Checklists.stoaryboard
2.删除ChecklistDetailViewController segue。
3.选择 ChecklistsViewController.swift
4.添加以下代码:它的工作没有segue
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let storyboard = UIStoryboard(name: "ChecklistDetail", bundle: nil)
let aVC = storyboard.instantiateViewController(withIdentifier: "ChecklistDetailViewController") as? ChecklistDetailViewController
aVC?.checklist = checklists[indexPath.row]
navigationController?.pushViewController(aVC!, animated: true)
}
5.comment prepare(for segue: UIStoryboardSegue, sender: Any?) 方法。
这里我明白了:
在使用时,storyboard reference 需要提及ReferenceID
然后您可以通过分别给出 stoarboard name 和 storyboardId
来获取
viewcontroller