从引用故事板访问视图控制器

时间:2017-04-18 12:30:19

标签: ios uistoryboard uistoryboardsegue

据我所知,引用故事板可用于制作具有相同故事板参考的多故事板。如果所有View Controllers层次结构都通过segue连接,则可以正常工作。

我想知道如何在视图控制器之间使用没有segue的引用故事板,因为一个视图控制器可能以多种方式使用,或者可能需要使用新引用故事板中的故事板标识符访问视图控制器。

请告诉我,我想使用没有segue的引用storyboard的视图控制器。

4 个答案:

答案 0 :(得分:0)

你可以这样做......

@IBAction func tapButtonToShowOtherController(_ sender: Any?) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    //storyboard identifier set in storyboard "userSB"
    let aVC = storyboard.instantiateViewController(withIdentifier: "userSB") as? AViewController          
    aVC?.udelegate = self
    self.present(aVC!, animated: true, completion: nil)
}

答案 1 :(得分:0)

在身份检查器中将id提供给故事板,例如" ViewController_id"

MyCartViewController* destVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MyCartViewController_id"];
[self.navigationController pushViewController:destVC animated:YES];

答案 2 :(得分:0)

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    MyNewViewController *myVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:@"myViewCont"];

答案 3 :(得分:0)

从故事板中选择您的viewcontroller,然后选择 identity inspecter 根据需要提供stoary board id

enter image description here

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.Here我修改了以下内容:

1.选择Checklists.stoaryboard

2.Remove ChecklistDetailViewController segue。

3.选择ChecklistsViewController.swift

4.添加以下代码:无需工作

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 准备(对于segue:UIStoryboardSegue,发件人:任何?)方法。

我明白了:

使用时,故事板参考您需要提及 ReferenceID

enter image description here

然后,您可以通过 storyboardId 提供 stoarboard名称 viewcontroller

相关问题