lppier
lppier

Reputation: 1987

Connecting outlets in Mac OSX - confusion

I come from iOS programming background. Now I'm trying to write a application in Mac OSX. I'm trying to connect my button in my interface file MainWindow.xib to a ViewController, as I would normally do in iOS programming to partition out the methods. However, I am only able to connect the button to AppDelegate.h - why is this so? I'm not able to connect the button to any other file, I've tried NSViewController, NSWindowController. It's possible for me to proceed by dumping all the methods in AppDelegate.h, but if possible I would like to group the methods out logically according to file.

What's the correct method to do something like this in Mac OSX?

Thanks in advance.

Here is my AppDelegate

#import <Cocoa/Cocoa.h>

@class MainLoop;

@interface AppDelegate : NSObject <NSApplicationDelegate> {

}

@property (nonatomic, strong, readonly)IBOutlet NSWindow *window;
@property (nonatomic, strong, readonly)MainLoop *mainLoop;


@end

Upvotes: 0

Views: 626

Answers (1)

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

Follow these steps: Demo project here

  • Create a new class derived from NSWindowController. In image it is OutletCollection.

enter image description here

  • Create an Object, set its class to OutletCollection.

enter image description here

  • Make this object as delegate for window.

enter image description here

  • Now you can create outlets.

enter image description here

Upvotes: 2

Related Questions