How to remove "Failed to instantiate the default view controller" warning? - ios

Within my storyboard I don't have any VC with the Is Initial View Controller checked as I am instantiating and setting the window.rootViewController programmatically within the app delegate.
My app is working perfectly however I want to remove the "Failed to instantiate the default view controller" message.
I found question regarding this on SO and the accepted answer stated that the warning will go away if the Main Storyboard File Base Name is removed from the info.plist (Programmatically set the initial view controller using Storyboards).
However my app does not have the Main Storyboard File Base Name entry in the info.plist, so is there something else I can do to remove this warning?

This is a similar question. Here the answers worked perfectly for me. Please check it out.
iOS 7 - Failing to instantiate default view controller

Select a random VC in your storyboard as the initial VC. This will cause the warning to go away and the option will be overridden by your code inn AppDelegate. This is the approach I use to remove the warning. Maybe more of a workaround, but it is simple and works great :-)

Related

iOS app launches to black view

I have been trying to run my Xcode project on my iOS simulator an iPhone but I only get a black screen. I have tried multiple solutions but none seem to work.
I have tried:
Setting main interface to "Main.storyboard"
Installing all views i.e.: width: any, height: any
Adding print statement to viewDidLoad to state that the view did in fact load (didn't print that the view loaded)
Resetting all content of the iOS simulator
Running on my iPhone
Setting initial view controller
None of these have solved my problem
Make sure in your AppDelegate that you are creating the variable window like so (right after the app delegate class declaration): var window: UIWindow?.
Without this line of code, your views will just never launch and your screen will stay black.
There might be many reasons for blank black view. But first check whether you have the window variable declared in your appDelegate as suggested by #john. If this doesnt work, check in the storyboard whether you have made your first controller as initial view controller.
You can also do this by adding rootviewController as the view controller you want in the window inside application:didFinishLaunchingWithOptions:
May be you use an empty UIViewController(). In my case I set a default value an empty UIViewController()

Can't change rootViewController in Appdelegate?

I design a soft Pin.
You can put 4 numbers twice and it will be your code. When you finished code assignment. The view will present segue (kind: Present Modally) to show another viewController.
Due to convenient, I would like to reset the View controller.
The Best way I found on the stack overflow is to reset rootViewController in the Appdelegate
Solution Here
When I follow the steps, I got an error below :
The Console shows :
Maybe the problem is the design in my storyboard
The upper one is original viewController
Can anyone figure out what's wrong with my code?
Thanks a lot!!!
The problem is from your Storyboard : you don't have a view controller with a StoryBoard ID EnterPinViewController.
Go to your Storyboard, select the controller and on side panel Utilities check the StoryBoard ID value.
Or change instantiateViewControllerWithIdentifier parameter with the one matching the Storyboard Identifier of your view controller.
Click on your controller in storyboard.
In right side panel go to identity Inspector (3rd button)
Set Storyboard ID to EnterPinViewController
You are all set to go further now!!

What it is the best way to release UIViewController in iOS

I'm currently building a little sample iOS app, i developed my UIViewControllers and views programatically, i'm targeting iOS 7+ devices and i have a simple question :
Here how i show a new controller
MySuperController *superController = [[MySuperController alloc] init];
[self.navigationController showViewController:superController sender:self.navigationController];
First i wanted to know if it's the correct way to show another view controller ?
Second imagine i'm performing those instructions in a LoginViewController that will be displayed just once (typically when the user launches the app) how can i release this loginviewcontroller after creating and showing another view controller ?
i know this question has been already asked but all the solutions presented are old/inappropriate (my sample app is ARC enabled which is by default enabled i think)
I'm new to this environnement any help/indication is appreciated thank you
As Roy Nakum says in his comment, if you are using ARC, your code is fine. You create your view controller using a local strong variable, then present it. At that point the navigation controller takes ownership of it. Since your strong reference is a local variable, it does not keep ownership after your method returns.
However there is another problem with your code. This line will likely cause you problems:
MySuperController *superController = [[MySuperController alloc] init];
You should not use init to create a view controller. It won't have any contents. You should either use initWithNibName:bundle: (to load a view controller from a NIB) or instantiateViewControllerWithIdentifier (to load a view controller from a storyboard.)
It is possible to set up a view controller so its "plain" init method loads it's views, but it takes special handling in the init method, and it's not the normal way to do things.
That's a good way to present a ViewController. If you have ARC enable (default) don't worry about releasing, it will release automatically.

Swift: App crashing during segue

I have 3 view controllers that I'm navigating between. When I open my app, I start at Controller1, which I can then use to navigate to Controller2 or Controller3. I can navigate to each of them fine individually, however, after I go to Controller3, return to Controller1, then try to navigate to Controller2, I get an EXC_BAD_ACCESS with code = 1. There is no exception or error message given at all, it just takes me to my AppDelegate file and gives me that error code.
I don't know what the issue is, but something that seems relevant is that I'm setting Controller3 as the navigation controller's delegate. I have a fourth navigation controller that also is set as a delegate as well, and causes the same behavior when I from 1->4->1->2, just like with 1->3->1->2. I have no issue going from 1->4->1->3 or 1->3->1->4, only when 2 is involved. I'm not sure if the issue is the delegates, and the fact that 2 isn't being set as one. Once again, I can navigate to it fine by itself, but not after navigating to one of the other 2 sub-view controllers.
If you set Controller3 or Controller4 as the navigation controller delegate then you need to clear it in the viewWillDisappear function of those classes otherwise you will end up with an invalid reference and that is what is causing your crash
I ran into this same kind of crash, so I will share what the issue was for me:
I had created a subclass of UIWebView.
In my storyboard, I dragged a UIWebView onto the canvas and changed it's class to be my subclass.
That was all working. The app had already passed through our QA team, was "accepted" by the business owner, and we were ready to push it to the app store.
Then I was told, "You can't use UIWebView. You must use WKWebView."
Fine, I changed my subclass to inherit from WKWebView, tweaked my internal class logic, and....splat. Trying to segue to that view controller would crash just as noted by the OP.
The problem was my storyboard: Because it was trying to instantiate my subclass, it was basically attempting to create a WKWebView which is NOT necessarily supported in Interface Builder (my friend says it might be ok in later versions, but I didn't verify).
TL;DR
The moral of the story is that if you have a subclassed object on your story board whose ancestor can't be dragged from the toolbox, then you will probably crash when you segue.

Is this a bug in Xcode 5 for iOS 7?

Create a new single-view project (e.g., 'Test')
Within the main storyboard, create two view controllers with titles One and Two - make One the initial view controller
Place the label One within the content of view controller One and label Two within Two
Include the following within the viewDidLoad of TestViewController.m:
// instantiate the new view controller
UIStoryboard *storyboard = self.storyboard;
TestViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"Two"];
// Change the view
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:viewController animated:YES completion:nil];
Save, build, and run.
I consistently get an error of the Storyboard does not contain view controller 'Two' variety. Using breakpoints, I've discovered that the problem is at the instantiation step. Yet the above code is taken directly from Apple's View Controller Programming Guide.
I've combed this site and discovered many people having problems with instantiating view controllers programatically. Any definite solution?
There's no bug here -- you're just writing inappropriate code. The code snippet you've given works fine if you put it in an action and trigger it with a button, a timer, etc. But you're attempting to present another view controller modally before the view controller running the code has even gotten around to displaying its own view.
-viewDidLoad is called when the view controller's view has been loaded from the storyboard or .xib file; it's an opportunity to do any initialization that had to be deferred until the view hierarchy comes into existence. However, the view isn't actually displayed at that point. You need to wait until you get a -viewDidAppear message to know that the view is on screen. So, you can imagine that it doesn't make a lot of sense to try to present some other view controller before the current one has even settled in.
I consistently get an error of the Storyboard does not contain view controller 'Two' variety.
In that case, you haven't properly assigned a storyboard identifier to the view controller. Select view controller "Two" in the storyboard editor and then look at the identity inspector. You need to set the identifier like this:
I've combed this site and discovered many people having problems with
instantiating view controllers programatically. Any definite solution?
Did you also look at the answers to their questions? That's how this site works -- we answer questions not just for the people that are asking them, but also to help others in the future who may have similar questions. Identifying a UIStoryboard is a good example of a question similar to yours with an answer that probably would have helped you.

Resources