views:

324

answers:

1

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
A: 
[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].
Peter Hosey
Makes sense to me, but when I try that code I get: "-[toDoViewController toDoButton]: unrecognized selector sent to instance"... For some reason, viewController (instance of toDoViewController) isn't recognizing that it has access to toDoButton.
iconmaster
As I said, you'd need to make that view controller an instance of a subclass in which you've added a `toDoButton` property.
Peter Hosey
Edited above to add my toDoViewController subclass definition. The toDoButton is defined as an IBOutlet, which is hooked up to the view controller in IB. Am I missing a step?
iconmaster
Yes: You have not made it a property. See the section on properties in the Objective-C 2.0 Programming Language: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html
Peter Hosey
That did it. Thanks much.
iconmaster