Reputation: 6472
I am making an attempt at my first Mac app. I have a bit of experience with Objective-C and iOS game apps, but have never used an XIB file or Interface Builder before.
I have created a MasterViewController class with XIB and can successfully get this XIB to show from the AppDelegate by using the following:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
[self.window.contentView addSubview:self.masterViewController.view];
self.masterViewController.view.frame = ((NSView*)self.window.contentView).bounds;
}
There is a single Label and a single Button on the screen, but I cannot figure out how to connect Button so that it fires an action when it is clicked.
Here is the MasterViewController.h
#import <Cocoa/Cocoa.h>
@interface MasterViewController : NSViewController
-(IBAction)testMessage;
-(IBAction)testAction;
@end
Here is the MasterViewController.m
#import "MasterViewController.h"
@interface MasterViewController ()
@end
@implementation MasterViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
-(IBAction)testMessage {
NSLog(@"testMessage");
}
-(IBAction)testAction {
NSLog(@"testAction");
}
Here is screenshot of Interface Builder:
When I look at the File's Owner section, my testAction does not appear in the list and I can therefore not drag to associate.
I am sure I am just missing something simple, but how do I assign MyButton1 click to my testMessage action?
I am using Xcode 6.1.1 on OSX 10.9.5
Thanks
Upvotes: 0
Views: 650
Reputation: 351
In order for your IBAction to trigger it has to be like the following:
- (IBAction)testAction:(id)sender {}
You're missing the (id)sender part.
If this doesn't work I have a few more solutions.
Upvotes: 1