Interface Builder won't allow me to select a nib name for tab bar - interface-builder

I just upgraded to xCode 4 and I am having so much trouble setting the nib name for a particular tab. If I choose nib name it drops down a list with nothing, if I just type in the nib name I want, when I run it, it does not show that view. And I have specified the class for that tab. I have a tab bar and a navigation controller set to one of the tabs.
Thanks

You can add an uinavigationcontroller to your uitabbarcontroller.
Now you can add an uiviewcontroller to the added uinavigationcontroller.
Now you can change the class of the last added uiviewcontroller, and set the nib-name for this item.

Related

Xcode Outlet/Action connection UITextField

I'm trying to add my text field as an Outlet in my ViewController.swift, but when I drag the text field from the Main.storyboard to the ViewController it only shows as action and I cannot change it to Outlet.
I had this problem too! I fixed it by clicking on the top bar of my UIViewController (in the storyboard looking window), then selecting the Identity Inspector on the right and in the top where it says Custom Class in bold there is a field called Class which I set to the viewcontroller file I was trying to control-drag the UITextField to. Once the Class was set to the right name I was able to control-drag for an outlet. I hope this helps.

Creating an outlet for a NSProgressIndicator inside a NSToolbar

I have this OSX storyboard-based application that starts with a NSSplitViewController like this:
This splitViewController has two viewControllers: master and detail.
Inside the window I have a NSToolbar. I dragged a NSProgressIndicator to that toolbar and Xcode embedded it inside a NSToolbarItem.
Now I need to create an outlet (not an action as explained on other stackoverflow questions) from the NSProgressIndicator to some class. First question is which one?
Xcode will not let I create an outlet. I have tried these options:
dragged from the ToolbarItem to masterController class file, detailController class file and to NSSplitViewController class.
dragged from the ToolbarItem to the delegate class.
dragged from the NSProgressIndicator to masterController class file, detailController class file and to NSSplitViewController class.
dragged from the NSProgressIndicator to the delegate class.
dragged from both the NSToolbarItem and from the NSProgressIndicator to the Window Controller First Responder.
In all cases dragging does not make a window appear to allow me to create the outlet.
For heavens sake, how do I create an outlet like that? To which class I drag it and how do I do that?
I'll assume your setup is more like this image:
Your Window scene is backed, by default, by an NSWindowController, to which you cannot add new outlets. You need to create a subclass of that, associate it with your Window and then you should be able to create outlets in that.
File > New File > Cocoa Class
Specify a name like "SpaceDogsWindowController", as a subclass of NSWindowController.
Then use select the window controller icon (blue circle) and select the Identity Inspector in Xcode. (CMD+ALT+3). Specify the name of your new class in the "Class" field.
Then try to hookup an outlet:
1) Show the Assistant Editor
2) Use the Jump Bar to ensure your custom class is visible (It's at the top of the assistant editor pane, it should say Automatic and you can tap that to then select your new class; If it says 'Manual', change it to Automatic).
3) If your are control-dragging and it's still not offering to make a connection, try dragging from the document outline (also shown in the screen shot).
You could then edit that progress indicator from other view controllers, which are descendants of that window's view hierarchy, using code like this:
if let windowController = self.view.window?.windowController() as? CustomWindowController {
windowController.progressIndicator.doubleValue = 0.4
}
or, in Objective-C, something like this:
CustomWindowController *myWindowControllerSubclass = self.view.window.windowController;
windowController.progressIndicator.doubleValue = 0.4;
Hope that helps.

Can't ctrl+drag into ViewController.h from second Viewcontroller

I am building an iOS app for fun and here is where I run into trouble. I can insert an outlet and action in the ViewController.h files directly from my first View Controller through the ctrl+drag method; however, when I try ctrl+drag on the second ViewController it will not allow me.
Ctrl+drag on first ViewController
Ctrl+drag on second ViewController
You have the wrong document open in the assistant editor. It should be ViewController.h, but you are displaying UIViewController.h.
Check you have correctly set your second view controller to your custom class ViewController using the Identity Inspector (third of the right hand utility panels) then make sure it's header file is the document you are displaying on the right.
update
From your comments, you are having difficulty setting the second view controller to a custom class.
Here is how you select it in the storyboard. Note that you are selecting the View Controller, not it's topmost View
Copy and paste the class in the field "Class." You then need to press ENTER to take effect. Example

How to add a bar button item in interface builder?

I am really new to iPhone development and I need help setting up my views.
I have a view that is named FirstViewController.xib and a controller class for this view.
In my MainWindox.xib I have setup a root controller with a moveToNextView function that is connected to the options bar button item.
So when I click on this item the current view switches to the first view and I am able to swticht back. That works fine so far.
The navigation bar at the top of the screen from the MainWindow.xib is displayed in the first view, too. But when I open FirstViewController.xib there isn't any navigation bar defined (but on build&run it is displayed).
This is a problem for me because I want to add a save bar item to the first view. How do I solve that?
Assuming you have a UIViewController (or UIViewController subclass) that is a child of a UINavigationController. Note, I'm using storyboards so your results may vary when using xibs.
If you do not see a UINavigationBar on the interface, try manually changing the simulated metrics.
Drag a Navigation Item onto the view (anywhere). You should now have a place to enter the title in the interface builder.
Now you can drag Bar Button Items onto the nav bar.
You have to do it from code. Add to your FirstViewController class viewDidLoad method:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Save" style:UIBarButtonItemStyleDone target:self action:#selector(doSave:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
Just drag a bar button item onto your nav bar in Interface Builder. Xcode automatically wires it up then you can use it like anything else...

Code Pattern: Loading TabBarController objects directly from independent .xib file (instead of from MainWindow.xib)

I've looked around online, and haven't been able to find an acceptable solution to this problem...
I'm looking for a simple code pattern:
Load a TabBarController object (with associated subview controllers) from a separate .xib file, instead of including and loading automatically from a default MainWindow.xib.
In XCode terms, starting from a new iPad/iPhone project as a "Tab Bar Application", the goal is to solve the following:
Create the project
Move: TabBarController, TabBar, FirstViewController, and SelectedSecondViewController from MainWindow.xib, into a new "TabBarController.xib" file
After moving, MainWindow.xib should only contain: File's Owner, First Responder, App Delegate, Window
In TabBarController.xib, File's Owner and First Responder are set to: UIApplication and UIResponder, respectively.
Change "didFinishLaunchingWithOptions" in the main application delegate to the following:
REMOVE:
[self.window addSubview:tabBarController.view];
ADD:
UITabBarController *uiTab = [[UITabBarController alloc] initWithNibName:#"TabBarController" bundle:nil];
[self.window addSubview:uiTab.view];
With these changes, the application builds and runs, but when the TabBarController loads the tab bar is "empty" -- there don't appear to be any contents in the controller.
In looking in the debugger, either the "init" isn't initializing from the data correctly, or something in the .xib file is not set correctly.
What is the correct solution to this? I realize there are other ways of doing this, and yes, I have them working in other applications.
What I'm looking for however, is a specific solution using the default project, that can be used as a general pattern for setting up iOS code.
Thanks in advance for any help
js
I think i know what you are looking for because i want the same thing.
Create New Empty xib file at interface builder.
Add to the xib TabBarController from the library.
Edit whatever you need on this tab bar controller on the xib.
Of course, save...
Determine from which view controller do want to create that xib with tab bar controller. In other words, who is the view controller that will cause this tab bar controller to appear.
Let's call that view controller ParentViewController
In that view controller, create an IBOutlet to a TabBarController.
Back to the xib, make the identity of the File's Owner to the ParentViewController and of course dont forget to hook up the outlet of the tab bar controller in the file's owner to the tab bar controller in the xib.
save the xib and you are ready to go.
When you want to present that tab bar, just decide which way you want to do it: Modally,Popup or something else (Not inside a navigation controller because Apple dont allow tab bar controllers to be inside navigation controllers).
When you decide, just present your tab bar controller outlet the way to present any other view controller. for example:
[self presentModalViewController:self.myTabBarController animated:YES];
Assuming you start with the "Tab Bar Application" template and move the UITabBarController and associated view controllers to a new nib as you described...
In your new nib, File's Owner should be set to your AppDelegate class. Then connect the outlet "tabBarController" of File's Owner to the UITabBarController.
Then in your -[application:didFinishLaunchingWithOptions:], do not remove this line:
[self.window addSubview:tabBarController.view];
Instead, load the new nib right before that with your app delegate as the owner:
[[NSBundle mainBundle] loadNibNamed:#"TabBarController" owner:self options:nil];
That will set your tabBarController property (since you made that connection in the nib) and then you can proceed as normal. What you were doing was actually creating a whole new UITabBarController, and not loading the one from the nib at all. (well, ok you were loading it for a brief moment, but then not doing anything useful with it)
Hope that helps.

Resources