Reputation: 628
How can I change the functionality of a button that I used previously? For example, If I had a button that did "Proceed/Cancel" and let's say you "Proceed" the button would change to something such as "View/Go Back"? Basically I want to re-use the same button for something else, but since I don't know how maybe someone can help me understand it better. Thank you.
- (IBAction)someButton:(NSButton *)sender {
if ([someString isEqualToString:someThing]) {
isAllowed = YES;
[oneButton setTitle:@"Proceed"];
[self continue];
}
else {
[oneButton setTitle:@"Cancel"];
return;
}
}
- (void)continue {
// I would like to make someButton (above) take on different functionality
// here if that's even possible. such as:
[oneButton setTitle:@"View"];
[self whatNow];
Upvotes: 0
Views: 463
Reputation: 18215
At some point in your program lifecycle you could replace the previous target and/or action of a NSButton
by the desired one.
[oneButton setAction:@selector(continue)];
This will cause your continue
selector to be called instead of the someButton:
for the oneButton
instance.
OBS: just pay attention at your selectors as the one from the NIB file has a parameter @selector(someButton:)
and the one you are creating does not have any, so it stays as @selector(continue)
as seen here: Cocoa forControlEvents:WHATGOESHERE
Upvotes: 3