How to add an outlet between a storyboard and an NSDocument - xcode

I've done iOS for a few years, but I'm new to OS X.
I'm using the document-based template in Xcode 6. I added a textfield to the view controller in the storyboard. How do I access it from the Document?
I added:
#property(nonatomic, weak)IBOutlet NSString* aString;
to Document.h. When I drag to it, IB seems to be forcing me to use bindings. OK with me, but I'm still very weak on bindings. The dialog box asks for a number of values, most of which I can guess. But, what does "Custom Class" mean, and what should I put there?
A little help here would certainly be appreciated.
Thanks

You don't. The IBOutlet for the textfield should be in the NSViewController subclass (ViewController in the template Xcode project).
Your next question will be "How do I access the NSDocument from my view controller?"; Mac App Storyboard - Access Document in NSViewController ;-)

Related

Xcode UICollectionViewCell xib not displaying any views added to it

I'm trying to create a custom UICollectionViewCell backed by a *.xib file.
However, when I try to add subviews to the cell, interface builder (as well as an actual instance of the cell inside the app) doesn't show them at all.
It doesn't matter whether I add in an UIView as a contentView or not, all subviews seem to be invisible.
This happens in Xcode 7.2 inside a tvOS project. Does anyone experience the same issue or can see what I'm missing?

Swift IBAction Issue With ViewController Swap OSX

I have 2 ViewControllers in an OSX swift project using storyboards. My aim is, when I click the button, the IBAction is called and the view also switches. However, despite my IBAction seeming to be good (I dragged it on and did println("hi")) "hi" is not printed, but the viewcontroller is changed. I would think it were an XCode glitch if I didn't know better, but for the life of me I can't think of what I'm doing wrong. Is anyone able to replicate this?
Can you paste the ViewController code? Is this the first time you hooked up an IBAction to that button? There might be an existing connection in the connections inspector which you haven't closed out yet?

NSWindow vs ViewController - OS X - Cocoa

I have been making iOS apps for a while now and I decided that I wanted to start working on making some of them for the Mac too.
The question I have is this: is there any need for an NSWindow, now that developing for the Mac is so similar to iOS??
So I made a simple cocoa application using Xcode and its comes with a storyboard called "Main", just like on iOS.
In that storyboard file, there is a NSWindow which then links to a NSViewController.
Can I get rid of that NSWindow? As I tried setting the NSViewController as the "Initial Controller" and the app still works fine. So whats the point of the NSWindow?
Also, what class links to the NSWindow? I was trying to blur that background of the NSWindow, but I have no way of linking code to the NSWindow.
Sorry for my stupid questions, but I am completely new to development for OS X.
Thanks for your time, Dan.
Those are many questions in one question:
Can I get rid of NSwindow? No, you need a window to show you views.
What is the point of the NSWindow? NSWindow is needed as the window in which the views are displayed and your events are going up the responder chain.
What class is linked to NSWindow? Obviously the NSWindow class, but that is not what you want to know. I think you want to know the delegate that controls NSWindow. This is NSWindowController, although for the MainMenu.xib it is NSAppDelegate.
Hope this gives you the answers you need. An example for working with views in a window is given in this question.
Please, see for further details the windows programming guide, which states:
The NSWindow class defines objects that manage and coordinate the
windows an application displays on the screen. A single NSWindow
object corresponds to at most one onscreen window. The two principal
functions of an NSWindow object are to provide an area in which NSView
objects can be placed and to accept and distribute, to the appropriate
views, events the user instigates through actions with the mouse and
keyboard.
For the question: Can I get rid of NSwindow? I have further comments. In most cases, You need a NSWindow to show view on screen; but in special case you don't, for example, a popup view when you click a NSStatusItem.
So my answer is whenever you need to respond window event such as min/max, you need NSWindow as the view container.

xcode 4.2 storyboard, segue by code

I'm trying to make the segue between a button created by coding and a view created in storyboard?
(the button is not in the storyboard, it's made inside the viewcontroller .m class)
please help if you know the solution
thanks,
If the current view controller (the one that owns the button) came from the storyboard, you can just use the performSegueWithIdentifier:sender: method of UIViewController, like this:
[self performSegueWithIdentifier:#"mySegue" sender:sender];

Xcode 4 and controllers with xibs

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?

Resources