问题描述:

Here is my storyboard image:

I want to create segue to viewController the red arrow is pointing to. This is a profile viewController. There will likely be three viewControllers linking to this viewController eventually. At present there will be two.

Now I can simply control drag show and create a segue. However this looks messy. My storyboard now has this diagonal line going underneath viewControllers.

Is this the expected way of doing this? Is it perfectly normal to have a line reaching from one up to another??

Thanks for your ans in advance.

网友答案:

In fact you can navigate your application to any of the viewCotroller anytime using segue or storyboard id. But there is a predefined rules here you must know about viewController's stack, whenever you load any viewController they appears in a stack which follows first in last out manner.

You can use segue to navigate your viewConteoller or storyboard ID.

Objective c:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewsId"];

// Note: use presentViewController or pushViewController one of them    
[self presentViewController:vc animated:YES completion:nil];

[self.navigationController pushViewController:vc animated:YES];

In Swift:

let vc: UIViewController =  (self.storyboard?.instantiateViewControllerWithIdentifier("viewsId"))!

// Note: use presentViewController or pushViewController one of them
    self.presentViewController(vc, animated: true, completion: nil)

    self.navigationController?.pushViewController(vc, animated: true)
网友答案:

You could actually just add the segue form the storyboard, and even with the diagonal line it would be ok. Just not for the eyes.

If you dont want your storyboard to get messy, you could instead put the profile controller in another part of the storyboard and then call it directly without using segues.

if let vc = UIStoryboard(name: "MyStoryboard", bundle: nil).instantiateViewControllerWithIdentifier(identifier: "viewControllerId") {
    // Present or push the view controller using the proper function
}

To set the view controller identifier you can just click on it on the storyboard and fill the "Storyboard ID" field in the identity inspector.

相关阅读:
Top