I have a problem with the Segue. All segues have an identifier.
I change from one view to the other by writing this:
self.performSegue (withIdentifier: "ready", sender: self)
This would work only if I open the app 5-10 times (always different) does the app crash with the following error message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<MyApp.4ViewController: 0x1180c7000>) has no segue with identifier' select ''
I do not understand why it does not work. The Segue with the identifier "select" is only between VC 1 and 3 but the Segue between VC 3 and Tabbar Controller (VC 4) has the identifier "ready".
func readyToGo() {
UserDefaults.standard.setValue(check, forKeyPath: "go")
UserDefaults.standard.synchronize()
self.performSegue(withIdentifier: "ready", sender: self)
}
Thank you very much
From your log you perform a segue at VC named 4ViewController with identifier select check your code , despite you say it's between 1 & 3 , check if make the segue back from vc4 to vc1 , may in viewDidAppear or when VC 4 overrided methods
Related
I want to switch between viewController by using containerViewController.
For this I created multiple segues and viewController.
when I run
func segueIdentifierReceivedFromParent(_ identifier: String){
self.segueIdentifier = identifier
self.performSegue(withIdentifier: self.segueIdentifier, sender: nil)
}
in it's parent controller file it works fine but when I called it through other controller file it gives error
ContainerViewController: 0x7fd703707b40>) has no segue with identifier 'second''
This is how i called it in other viewController
let vc = ParentViewController()
vc.segueIdentifierReceivedFromParent("second")
Here "second" is the Identifier given to segue in storyBoard
Above code is written in AddTarget of button.
So when I tap button I get Error
If you are in same a storyBoard then you can simply do this -
Take a button in your firstVC and ctrl + drag a segue upto your secondVC. Then click on the segue. (the round thing on between two view controller). -
And set a identifier for that (here about is the identifier, you can give any name for this)-
Here is the code -
#IBAction func UserDetailVC(sender: AnyObject) {
self.performSegue(withIdentifier: "segueIdentifierName", sender: sender)
}
when user clicked button
let uvc: UINavigationController =
self.storyboard?.instantiateViewController(withIdentifier: "nationSelect") as! UINavigationController
uvc.modalTransitionStyle = UIModalTransitionStyle.coverVertical
self.present(uvc, animated: true, completion: nil)
run this code.
identifier:nationSelect storyboard img
cell, closebutton, VC segue unwind img
and
button vc have this function
#IBAction func unwindFromPostCodeSelectionView(_ sender: UIStoryboardSegue) {
print("unwindFromPostCodeSelectionView")
}
and nationSelect VC
when collectionview's cell clicked
run this code
performSegue(withIdentifier: unwind, sender: nil)
and prepare function
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let identifier = segue.identifier, identifier == unwind else{
return
}
guard let vc = segue.destination as? CurationRequestViewController else {
return
}
vc.getAddress.setTitle( (continent.text ?? " ") + " " + nation , for: .normal)
}
but i got this error
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'unwind''
help me plz!!!
Looks like you are trying to implement unwind segue and you missed to specify the identifier for unwind segue.
Here are the steps to properly implement unwind segue:
Step 1: If you are trying to implement unwind segue from Vc2 to Vc1 (Coming back to VC1 from VC2) then in VC1 add the IBAction as
#IBAction func unwindToViewController1(segue : UIStoryboardSegue) {
//you will get control back here when you unwind
}
Step 2:
Open storyboard, select VC2 and control drag from ViewController to Exit option in storyboard as shown below
This should show a popover and the method you just declared select it.
Step 3: (Step I think you missed)
Select the unwind segue you just added and provide a identifier to it.
Step 4:
Now whenever you wanna return back to VC1 you can simply call
self.performSegue(withIdentifier: "unwindSegueToViewController1", sender: nil)
Hope it helps :) Happy coding
I made a manual Segue to a Collection View Controller but there is a error.
This is the segue code.
func showChatViewController() {
performSegue(withIdentifier: "toChatLogController", sender: self)
}
Yes it is very very basic
but there is error like this
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] instantiated view controller with identifier "UIViewController-mj8-fl-tie" from storyboard "Main", but didn't get a UICollectionView.'
In my code I need to go through a navigation hierarchy, which is why I have a UIViewController in a UINavigationController.
If the user tabs on a cell and there is a next level, I create the same UIViewController again and push it on the UINavigationController. This works fine.
But when I reach the end of the hierarchy and try to performSegueWithIdentifier, to go to a different controller to see the details, the app crashes and says
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<myproject.MenuController: 0x7fb2e0ea9ef0>)
has no segue with identifier 'showDetail''
However I checked InterfaceBuilder, all fine.
Interestingly, If I don't push a next level of navigation and perform the segue to the new controller directly, all works well.
I also tried to push the new controller, like I'm doing with the navigation, but then it tries to access the new controllers delegates which strangely are nil and crashes.
Somebody know how to do this?
Complete code (inside MenuContoller)
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
//self.performSegueWithIdentifier("showDetail", sender: self)
let clickedCell = self.tableViewItems[indexPath.row]
print("Selected \(clickedCell.itemID)")
// Check if subview has children, then we push a deeper level on the navigation controller
if (menuItems.filter{$0.parentID == clickedCell.itemID}.count > 0) {
let subNavigationController = MenuController()
// Set the currentNavigationItemID for the new view controller
subNavigationController.currentNavigationItemID = clickedCell.itemID
subNavigationController.title = clickedCell.itemDisplayName
self.navigationController?.pushViewController(subNavigationController, animated: true)
} else {
// Load new Controller to show details
self.performSegueWithIdentifier("showDetail", sender: self)
// let subNavigationController = ProductListViewController()
// subNavigationController.currentCategoryID = clickedCell.itemID
// self.navigationController?.pushViewController(subNavigationController, animated: true)
}
The problem is that your MenuController has not been created from the Storyboard, so it has no segues attached to it.
You need to ask the Storyboard to create the MenuController, so instead of:
let subNavigationController = MenuController()
you need:
let subNavigationController = self.storyboard?.instantiateViewControllerWithIdentifier("menuControllerID")
For this to work, the storyboard ID must be set in the Identity Inspector to "menuControllerID" for MenuController.
I am trying to understand how the unwind segue works. First I created 3 ViewControllers.
GlobalVC
-LoginVC
-RegisterVC
I set the initial page the GlobalVC (only authenticated user can see). I set a segue from:
GlobalVC to LoginVC called globalToLogin and LoginVC to RegisterVC called loginToRegister. Here is my storyboard:
For the registerToLogin direction, I used this work-around (in RegisterVC), but looks a bit ugly.
#IBAction func unwindToLogin(sender: AnyObject) {
//Dismiss View
dismissViewControllerAnimated(true, completion: nil)
}
However, now I am trying to direct from LoginToGlobal
First, I selected Login button, dragged it to LoginVC:
#IBAction func loginButton(segue: UIStoryboardSegue) {
performSegueWithIdentifier("unwindToGlobal", sender: self)
}
After setting segue: UIStoryboardSegue, now it gets available to right-click on Exit. But, I got confused here. Whatever I tried to drag the circle inside Exit to, it gives an error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', >reason: 'Receiver (0x7fdd2068a480>) has no segue with identifier 'unwindToGlobal''
Where should I drag the circle on? ( I keep seeing Unwind segue to 'Exit' )
The unwind action method is defined in the destination view controller (e.g. in GlobalVC).
#IBAction func unwindToGlobal(segue: UIStoryboardSegue) {
// this may be blank
}
And then, when you're hooking up the button to this action, you don't drag to the code sample, but rather to the "exit outlet" icon above the scene:
See this answer for more screen snapshots.