viewDidLoad not being called by parent UITabBarController - objective-c

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.

Related

NSDocument init not called in one pane of split view controller in a storyboard

I have a document-based application that works.
I added an NSSplitViewController, pointed the storyboard entry point to it, moved the document's view controller to a pane in the split view controller, and moved the document's view to one of the split view controller's views. The other split view controller view will contain info that is not part of the document but will serve as a source for info that the user may add to the document.
Everything seems to work fine, except my document's init method is never called. I don't understand enough about the application initialization process with respect to the storyboard to fix this.
Any suggestions?
Are you linking your documents view controller in storyboard to a your class?
In [myTableViewController viewDidLoad] I added an explicit call to [[Document alloc] init] which did the trick.
I still don't know why I did not have to do this in the simpler version, but I have to move on. I've wasted too much time on this as it is.
Thanks for looking at this question.

Setting an identifier for an Xcode Storyboard Segue in a UITabBarController, and getting a pointer to its view controller

This is my first app using storyboards/segues, and I'm pretty sure the answer to this is easy, but I'll be as thorough as possible in describing my issue.
I am making a simple app which has a Tab Bar Controller scene and two View Controllers.
My app launches by being sent a URL from another app. The application:openURL:sourceApplication:annotation: method in the app delegate performs some work to determine
which tab to display first, and
what information to display on it.
My goal is to use the performSegueWithIdentifier method (I'm open to alternatives though) from within the AppDelegate to select the tab, and also find a way to send a method to the instance of the view controller created by the storyboard.
Issue #1 is that I can't set an identifier. When I select the tab "relationship" there are no choices available in the Attributes Inspector (it says "Not Applicable"). How do I set a name for this segue? Can I? Or is there some rule under which UITabBarController segues can't be trigger programmatically?
Issue #2 is that I can't find a way to have a pointer to the view controller. Pre-Storyboard I would alloc and init a new view controller and then set it up, but here if I do that, it does not get displayed when my app launches (I think this is because Storyboard is displaying a different instance of the same view controller.)
I know this post is long, but I feel like I'm missing something simple. What is it?
Sounds like you need to have your AppDelegate set the entry point to your storybard.

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.... :)

IBOutlet UIViews are null?

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

The UIButtonBarItems and UIPopovercontroller references in UISplitViewController delegate methods

I could use some clarification regarding where these references come from. As an experiment, I set up a split view controller in my application. When the delegate methods are called, they reference what appears to be a valid UIButtonBarItem and a valid UIPopoverController. I say "apparently" because both of these have non-nil values and resolve to the appropriate class (UIButtonBarItem and UIPopoverController). I did not allocate or initialize either one. Am I supposed to?
I don't see anything in the reference documentation that requires that I initialize these programmatically or says how it should be done. I also don't see where the toolbar that contains the UIButtonBarItem is referred to. I haven't found any examples of tutorials that address this detail more than superficially. If someone can explain or provide a reference to an explanation, that would be helpful.
I am working out how to switch from split view to popover view when going into the portrait orientation. I want simply link an existing button to code that does what the UIButtonBarItem would do. I have a small banner view of my own that serves as a toolbar, and I would rather adapt the button in that to work with the split view controller, if I can.
The UISplitViewController creates both of these for you and you can do with them what you want. Just add the button that it provides you to your toolbar and store a reference to the popover (so that you can dismiss it, etc.).
Note that when you go back into landscape mode you need to set your popover variable to nil and remove your button since they are no longer valid.