IBOutlet UIViews are null? - objective-c

I have a class called ActorController and it has a NIB file. I have created IBOutlets in ActorController.h that match up with various UIViews and UIImageViews in the NIB file. However, these views never show up on the screen like they should. Upon further investigation, I have discovered that if i use NSLog to print the UIView object to the console, it prints null. Could anybody suggest what I may be doing wrong? Any help is appreciated.

Some things to look for:
Nib not loading at all:
wrong name
nib file not included in project
capitalization problems (iOS is case-sensitive on the device)
outlets not connected (views should still show up on screen, though)
outlets connected, but to wrong object
view controller created and initialized properly, but not displayed
active view controller is not the one you initialized from the nib

Related

iOS6 xib error "loaded the "ViewController" nib but the view outlet was not set.'"

I have read several other posts on SO about this and all say there is an issue with my view not being set on the File Owner. This makes sense, however my view IS set as well as all of my other connections in the XIB and I keep getting this error.
I tried using the loadView approach instead of viewDidLoad approach and it loaded just fine, however it is a "widget-intensive" app so I'd prefer to use a xib if possible.
It was working earlier, but then I made some massive changes. However as it is just a simple app for fun, I wasn't bothering with source control so I can't go back now.
Any idea how to debug this kind of problem or where to start looking?
Cheers
You have a very specific error message so it should not be too hard to debug.
Make sure you are looking at the correct XIB -> try deleting the XIB and see if it complains that the file dosnt't exist.
Check the class type of the files owner. It must match the ViewController you are tying to initiate. If it doesn't, set it correctly.
Check the view outlet dons't have a yellow warning next to it. If so delete the outlet and remake it.
Check the line of code you are initing the view controller with. Check it has the correct class and nib name.
Check that the XIB is included in the target.

Two view controllers (with nibs) acting on the screen at the same time

Just as a disclaimer, I am an iOS beginner, in a pretty unique position. I'm an intern learning on the job, with a hard deadline for a test app, with specific specs. So I unfortunately don't have the luxury of learning all that I should about xCode and objective C.
Anyways, I am trying to create a navigation menu similar to the iPad's slide out menu. I've looked at plenty of sample code given in response to questions like this in the past. It all works perfectly fine, but I can't understand all of what they're doing. I think this results from being fairly bewildered by view controllers and delegates. And, since I'm supposed to be writing this all by myself, I can't just build off of their existing code.
My plan for this working is to have one main view controller, containing the navigation menu in a table view. This is hidden behind a normal UIView, until a button is pressed, at which point the normal UIView slides offscreen enough to reveal the menu. Upon selection of a menu item, the normal UIView would slide back to its original position, and be replaced by the relevant UIView, controlled by its view controller. In other words, clicking on the menu item relating to "Home" would load the homeViewController.xib, controlled by the homeViewController. This would be loaded in that normal UIView subview, on top of the tableView.
I'm able to load a view in that normal UIView as a result of a button press.
homeViewController *_homeViewController = [[homeViewController alloc]initWithNibName:#"homeViewController"];
[self frontView] = _homeViewController.view;
There may be some syntax errors in that code, since its from memory. I'm not able to access the computer with my code on it at the moment, but that's the general gist. Basically, that places the home view nib on the frontView (that normal UIView that's over the table view), but its not connected to homeViewController. Or at least I think that's the issue, when I press a button, that's correctly connected between the nib and the homeViewController.h, and only set to NSLog in the .m file, the application crashes.
Any idea how to connect this nib to its viewController when displayed in this way? Or, to create the nib in IB, without the associated .h and .m files, and use the main view controller as the homeViewController as well? Or, if my logic is inherently flawed, what SHOULD I do? Something with NavigationControllers?
EDIT:
I also tried a new approach- changing homeViewController's file owner to viewController, and connecting the button on homeViewController's action to viewController. This too caused a crash upon pressing the button. I really think the issue is with having multiple view controllers acting on screen at once, or having multiple views from separate nibs, controlled by one view controller on screen at once.
I suspect that your immediate problem is that _homeViewController is being freed as soon as you leave whatever method that code is in. To fix this, create a strong property in this class that holds the _homeViewController for as long as its view is needed and allocate it to that property rather than a local variable. That way, buttons (or whatever) that are part of that view still have a valid controller object backing them.
In the long run, pushing or presenting view controllers when you need the screen to change is a much better strategy but, as I said, the immediate problem.... :)

xcode 3.1.4: nib controller doesn't seem to find nib file?

So I've got a MyNibController class and an nib file which I've tried calling both MyNib.xib and MyNibController.xib with no luck. I think I've got them hooked up properly on the IB end (I was following a tutorial for xcode 5 though) with my nib's owner designated to be of class MyNibController.
The problem is that the view is apparently not loaded even after I run my applicationDidFinishLaunching method in my AppDelegate class which includes:
[window addSubview:myNibController.view];
The simulator shows a blanks white screen, and the documentation says if a subclass of UIController can't find a nib with the right name it just makes up a blank view, so that's why I'm thinking it can't find it. But then wouldn't that mean:
[myNibController isViewLoaded]
should return true after the first code runs?
Thanks for any assistance!

Iphone : what do I need to do to a nib file to an exisitng object

I have tried using an outlet to connect my tableview controller to my object, setting the nib name in IB and setting the class in IB but it still wont link? I know this as im trying to set my table view to 'grouped'
Thanks very much.
It's a little unclear what the problem is. Do you have the outlet visible in IB, but it's not letting you draw a little line to the table view? In that case, double check the class of the outlet. It should be the same (or a superclass of) what you're trying to hook up to it.

viewDidLoad not being called by parent UITabBarController

Sample:
I've created a minimal set of files that highlight the issue here: http://uploads.omega.org.uk/Foo3.zip
If viewDidLoad/viewInitWithNibName are called, a message box is displayed. The message box is not displayed, therefore, the methods are not being called.
Details:
I have an application that is attempting to use a UITabBarController to switch between multiple views.
The views are linked up to the UITabBarController using interface builder (select the tab page, open Attributes (Option-1), and fill in the NIB Name field), and so are displayed "automatically" with no extra code-behind to make them appear.
Is it intended behaviour that views loaded like this do not have their viewDidLoad method executed? If not, how am I doing it wrong, and what do I need to change.
If it is intended behaviour, I can think of a few work-arounds, but any suggestions are appreciated:
Scrap the UITabBarController and implement the view switching myself (using initWithNibName and add/insert/push/Subview).
Call each of the children's viewDidLoad method manually in the UITabBarController's own viewDidLoad method.
Thank you in advance for any help you can offer.
OK, I've managed to solve this.
Linking the NIB to the TabBarController isn't enough - you also need to link the code beind file, it is not implicitly linked by the NIB even if you set the file owner correctly.
Open IB, and select the relevent page. Click in the middle to select the view controller. Enter the NIB name of the sub view, then go to the last page (option 4). In 'class identity', enter the name of the code-behind file for the sub-view NIB.
Everything will now work nicely.
I've uploaded a correct version of the sample code: http://uploads.omega.org.uk/Foo3-Correct.zip
You're not instantiating ImportedView anywhere in your project, so it's not calling either initXXX or viewDidAnything. If you put your alert code in -[FirstViewController viewDidLoad], it'll fire as expected.