Reputation: 1
I'm now developing mac application for the first time. So here's my problem. At first time launch, the application shows login form inside a custom view in the main menu xib file, the login form is loaded from another NSViewController
file. The problem is when I click the button at login form which is loaded in the main menu, it doesn't respond on click event. I've tried using performselector
method, add Action
, also using IBAction
, none of them works.
Here's the code of appdelegate.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSViewController *loginformcontroller = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
[window setContentView:loginformcontroller.view];
}
and at LoginViewController.m
@implementation LoginViewController @synthesize usernametxt,passwordtxt,loginbtn;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
[loginbtn setAction:@selector(checkalogin)];
}
return self;
}
-(void)checkalogin{
NSLog(@"masuk");
}
Any suggestions?
Upvotes: 0
Views: 691
Reputation: 2383
I don't know if it is the same case as mine , but if you extend that NSButton
and you override some of the methods like (void)mouseDown:(NSEvent *)theEvent;
do not forget to call [super mouseDown:event]
Upvotes: 0
Reputation: 15015
Include this line after loginbtn setaction:-
[loginbtn setTarget:self];
Upvotes: 3
Reputation: 1956
I assume loginbtn has its equivalent in Interface Builder. If so, justctrl+drag from button to view controller to create an IBACTION. No need to add action in code.
Upvotes: 0
Reputation: 150615
You seem to be dynamically setting an action for a button loaded from a nib.
It is possible that you have not actually hooked up the button to an IBOutlet in the view controller, which means that you are setting a target action for a nil object.
A better way would be to hookup of the buttons action to the correct method from within Interface Builder itself.
Upvotes: 0