My app have categories and this categories can have infinite subcategories or videos. My principal View controller have a uicollection vith cells. I need that that when i select a category, if the category have subcatehories then create other view controller like this the first with subcategories, but if the category have videos go to other different view controller.
i think that i need two segues from my cells in my principal view controller:
I want to drag a segue from my cell of my voew controller, to itself. So I can push "infinite" instances of that particular view controller(for all possible subcategories).
But i dont know how drag a segue from view controller to itself. when i try to drag a second segue xcode deleted my first segue.
thanks you friends.
just create custom segue from the code. You aren't then limited to only one segue like when using storyboards.
UIViewController *toViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"OtherViewControllerId"];
MyCustomSegue *segue = [[MyCustomSegue alloc] initWithIdentifier:@"" source:self destination:toViewController];
[self prepareForSegue:segue sender:sender];
[segue perform];
or create a view controller with ID and push it
UIViewController *myController = [self.storyboard instantiateViewControllerWithIdentifier:@"MyController"];
[self.navigationController pushViewController: myController animated:YES];
Here is an answer in Swift based on @MaciekWrocław
let destinationViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DestinationViewController")
let segue = UIStoryboardSegue(identifier: "SegueToProfileViewController",
source: self,
destination: anotherProfileVC,
performHandler: {
self.navigationController?.show(anotherProfileVC, sender: self)
})
self.prepare(for: segue, sender: user)
sege.perform()
Swift 4:
First, add this class extension on UIViewController somewhere in your codebase:
extension UIViewController {
class func storyboardInstance(storyboardId: String, restorationId: String) -> UIViewController {
let storyboard = UIStoryboard(name: storyboardId, bundle: nil)
return storyboard.instantiateViewController(withIdentifier: restorationId)
}
}
Then instantiate an instance of YourViewController class (using the extension above), and push to it from your navigationController:
let destinationVC = YourViewController.storyboardInstance(storyboardId: "YourStoryboardName", restorationId: "idYouSetInStoryboard") as! YourViewController
self.navigationController?.pushViewController(destinationVC, animated: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With