Question

I've subclassed NSViewController with IBOutlets hooked into an NSButton in a secondary nib.

I can instantiate the NSViewController and apply the view in an NSMenu -- it works great -- but how do I access the button to change its title?

Since the NSViewController has IBOutlets, I assumed I'd do this through the controller.

//this part works great
NSViewController *viewController = [[toDoViewController alloc] initWithNibName:@"toDoView" bundle:nil];
NSView *newView = [viewController view];
newMenuItem.view = newView;

//this part not so much
[viewController [toDoButton setTitle:someStringHere]];

Any pointers on where to go from here?

Edit to add: the toDoViewController class --

@interface toDoViewController : NSViewController {
    IBOutlet NSButton *checkBoxButton;
    IBOutlet NSButton *toDoButton;
}

@end
Was it helpful?

Solution

[viewController [toDoButton setTitle:someStringHere]];

As the interactive fiction interpreters would say, “That seems to be missing a verb.”

You have a receiver (viewController), and a complete message-expression ([toDoButton setTitle:…]), and brackets, but you are missing a selector. As such, this isn't a valid message-expression.

There are two possibilities:

  1. You mean to send a message to the view controller, passing the result of setTitle: as its argument, and you forgot the selector. I find this unlikely, because NSButton's setTitle: doesn't return anything.
  2. You mean to get the button from the view controller, then send the button a setTitle: message. Assuming that this view controller is an instance of a subclass of NSViewController in which you've added a toDoButton property, use either [[viewController toDoButton] setTitle:someStringHere] or [viewController.toDoButton setTitle:someStringHere].
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top