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.'
Related
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
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "mainViewController")
self.present(homeViewController, animated: true, completion: nil)
My code complies fine, however when I hit the third line in that sequence my whole application crashes and I get a Thread 1: Signal SIGABRT on that line and this is what appears in the console:
libc++abi.dylib: terminating with uncaught exception of type NSException
This only happens when I try to switch view controllers programmatically. I can switch view controllers normally by connecting buttons to view controllers in the storyboard, but I cannot successfully transition view controllers without having the user hit a button. Does anyone know how to fix this error, or an easier way to transition between view controllers.
Edit: I have also tried this:
let nextViewController = mainViewController(nibName: "MainViewController", bundle: nil)
self.present(nextViewController, animated: true)
Which also did not work but still compiled just fine.
Edit 2:
Before the main error message I get this warning in the console:
objc[45953]: Class VCWeakObjectHolder is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/AVConference.framework/Frameworks/ViceroyTrace.framework/ViceroyTrace (0x127e2d4d0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/AVConference.framework/AVConference (0x126f7be38). One of the two will be used. Which one is undefined.
Make sure that you have set the "Storyboard ID" in your for the view controller in your storyboard.
I created a workspace with 2 projects in it, let's call them A and B, with bundle identifiers com.domain.a and com.domain.b respectively. Each of the projects has a story board called Main.storyboard in them. I have a button in the storyboard of project A and I want to instantiate a view controller from the storyboard in project B with the following code:
#IBAction func clicked(sender: AnyObject) {
let bundle = NSBundle(identifier: "com.domain.b")
let storyBoard = UIStoryboard(name: "Main", bundle: bundle)
let vc = storyBoard.instantiateViewControllerWithIdentifier("aVC")
self.presentViewController(vc, animated: true, completion: {})
}
I also have set the storyboard ID for the view controller in project B:
But when I build and run the project I get this exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x7f8578cd34d0>) doesn't contain a view controller with identifier 'aVC''
NOTE: I used breakpoints and found out that the variable bundle in my code in nil. why?!
I'm using a segue in code from one view controller to another view controller, they are both embedded in a Navigation Controller, the segue is "Show".
This is how I call the segue:
performSegueWithIdentifier("LogIn", sender: self)
And this is what I do:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "LogIn" {
segue.destinationViewController.setShowsCancelButton(false, animated: false)
}
}
And as soon as the segue is triggered I get an error in Xcode :
[Chooze.LogInOrRegisterViewController setShowsCancelButton:animated:]: unrecognized selector sent to instance 0x7f928b93aed0
2014-09-23 16:40:04.608 Chooze[9935:939290] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Chooze.LogInOrRegisterViewController setShowsCancelButton:animated:]: unrecognized selector sent to instance 0x7f928b93aed0'
Since the destination view controller is embedded in a navigation controller, your code is trying to invoke setShowsCancelButton on the navigation controller. Instead, you should access the navigation controller's topViewController property, and call setShowsCancelButton on the object it returns, for example:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)
{
if segue.identifier == "Login" {
let navController = segue.destinationViewController as UINavigationController
let controller = navController.topViewController as LoginOrRegisterViewController
controller.setShowsCancelButton(false, animated: false)
}
}
I am trying to instantiate a view controller from the nib file like following :
class TNAChallengerHandler:ChallengeHandler {
var controller : ViewController
// Default initializer
init(realm iRealm: String, controller iController : ViewController) {
println("Default initializers")
self.controller = iController;
super.init(realm: iRealm)
}
// Convience initializer
convenience init() {
println("Convience initializers")
let vc = ViewController(nibName: "ViewController", bundle: nil)
self.init(realm: "SingleStepAuthRealm", controller:vc)
}
Executing the codes and I am getting
iOS_SingleBasedAdapterAuthentication[40828:5708548] *** Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/tonytran/Library/Developer/CoreSimulator/Devices/6B797313-635F-4ABD-B3C6-A1D9DF3F1E85/
data/Containers/Bundle/Application/FDC3FD2B-6E26-4654-AC0F-ED3F44DDC5F6/iOS_SingleBasedAdapterAuthentication.app> (loaded)' with name 'ViewController''
I double check in the storyboard, the custom class of the class is already changed to ViewController like below and the name is as same as ViewController.swift
Any thoughts about this. All comments are welcomed here.
You don't have a nib file named ViewController.
You have a storyboard. A storyboard is compiled into a set of nib files, but you don't access those nib files directly. Instead, you need to give your view controller a Storyboard ID. Then you can ask the storyboard to instantiate that view controller.
Let's say you use “GetData” as the Storyboard ID:
and I assume your storyboard is named Main.storyboard. Then you can instantiate the view controller like this:
convenience init() {
println("Convenience initializers")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("GetData")
self.init(realm: "SingleStepAuthRealm", controller: vc)
}
That said, I'm not sure it makes a lot of sense to instantiate a view controller by name when that view controller is also used as the root view controller of a UINavigationController. Are you sure you want to instantiate a new view controller here?