I have main xib with a splitview controller and ive dragged the ibactions and properties on to the AppDelegate code.
So in my applicationDidFinishLaunching i would like to load a controller which uses a xib into one of the nsviews that i have linked up.
The problem is that i can't use xcode to link ibactions and properties from the new xib into the controller that is going to load it.
Does that have to be done programatically?
I'm unsure of exactly what you are trying to do. However, it sounds like the 'splitview controller' you are referring to should be a subclass of NSViewController, then it can manage the xib for you.
Again, I'm not certain what you are trying to do; perhaps post a snippet of code?
Related
I often make use of views in interface builder that live outside of the viewcontroller hierarchy (see screen grab below for simple example).
Before upgrading to Xcode5 I could get this view to appear on the storyboard by writing an IBAction outlet and dragging a connection from the code to the view in the storyboard.
If you paused over the button for a moment it would flash and then open up as a view on the storyboard that is then a lot easier to work with.
Since upgrading this function no longer seems available. Has anyone found out how to get these views to appear on the storyboard?
Edit:
Using the temporary viewcontroller as described in this answer seems one approach, although fiddly since you need to move the UIView stack between viewcontrollers each time you want to edit the layout. Using a separate XIB is starting to seem like the sanest approach.
https://stackoverflow.com/a/13713385/1060154
Finally, we get this back in Xcode 7.
Hallelu!
I find it very convenient to use storyboards, especially to have (and show) an overview of the application.
However, I also find it very annoying to replicate the same code and views without the possibility to keep at least a reusable library of the most common xibs.
This is especially true with UITableView and its cell.
Did some of you have had any idea or best practice to share for dealing with this issue?
I was just looking at this yesterday, and it doesn't appear to be possible just yet. I've decided to go for the good old nib in case I want to be able to reuse a view. You can still use them while your main UI is defined in a storyboard using
UIView *view = [[NSBundle mainbundle] loadNibNamed:#"Nibfile" owner:self options:nil];
I tried this for about two weeks when finally discovery that you have to define if you will work with storyboard or xib files. They aren't going to work together.
I think that is sad too, but until the moment, there's nothing to do about it. The storyboard don't call your xib files and the segues will not work too.
According to several other posts - search storyboard and xib - people are currently using xibs and storyboards together, where xibs can be used to handle re-usable views. When you create a new file -> iOS -> View or Window, xcode creates a xib for you.
I have a UIViewController subclass that I created previously that had its controls laid out in a XIB file.
I'd like to use this view controller in a storyboard now, but it seems although I can indicate a view controller's classname in the storyboard, I can't tell it to load the XIB.
I'd rather not move everything from the XIB to the storyboard but keep it in its separate XIB.
How can I get this UIViewController in the storyboard to load my XIB?
Delete the View contained by the view controller in the storyboard.
Then provide the view by configuring a nib file with the same name
as the view controller class. For example if the view controller
class is called MyViewController, name your xib file
MyViewController.xib.
EDIT Note that Swift seed 5 started breaking this technique, because it mangles the name of the .xib file it's looking for. See my answer here for workarounds: https://stackoverflow.com/a/25539016/341994 Basically this name matching was broken in iOS 8, but then Apple repented and fixed it so that it works again in iOS 9.
I have a question regarding setting up a simple single view application. From what I can see there are two methods...
METHOD_001
Start Xcode and create a "Window Based Application"
Start setting up your interface in the MainWindow.xib
METHOD_002
Start Xcode and create a "Window Based Application"
In Xcode add a UIViewController subclass with its own XIB.
In Xcode add an IBOutlet to the delegate to point to UIViewController
In Interface Builder add an instance of UIViewController and link it at the delegate
In Interface Builder select the "NIB Name" the UIViewController will use.
To my mind METHOD_002 would seem to be the way to go for anything other than the most simple of tests. Also its following the MVC methodology, so I would suggest that METHOD_001 is just a starting point and you should always be heading towards METHOD_002?
gary
Between the two alternatives, the second one looks better for the simple reason that it has more loose coupling, probably making it easier to switch things around later. I'm not sure you could say that it's more MVC, because at this point you don't yet have any model objects, and even with the first method you have both a view controller and a view.
I'm looking in to using NSWindowController and I just can't think how to get it working. How do I start using it?
It's difficult to answer this question without knowing what you're trying to do. However, if you are writing a document-based application, an NSWindowController is automatically created for each window you create, so you don't need to create one specially.
The way I use NSWindowController is I create a different subclass for each type of window in my application. For example, I might have a 3D application with an AppWireframeWindowController and an AppPreviewWindowController. Each subclass automatically loads the correct nib file, and has code that hooks the document's data to the views in the nib.
If you are using storyboards you can connect an NSWindowController subclass up in IB. Otherwise if you are using nibs and have just the default template for a Mac Cocoa app then you may need to make it in code or just use a subclass of NSWindow.
Otherwise you can create a new NSWindowController and check the 'Also create XIB file for user interface' and it will give you the nib and also the NSWindowController subclass. It is basically a new nib where 'File's Owner' is your NSWindowController and the Window is the .window object inside the NSWindowController and the delegate is also pointed there.
You may be able to modify that.