Question

Just a quick semantic question, but is it considered OK to have multiple IBOutlets, located in different classes, going to one (for example) NSButton in Interface Builder. The reason I ask is I need to enable and disable an NSButton based on events that happen in different classes. Would multiple IBOutlets be OK, or should I be creating a controller class for the Button that would receive a message telling it to change the sate of the button, resulting in only one IBOutlet?

Thanks in advance.


@Wain

The relevant code for the MergeFilesController.h file:

@property (nonatomic, retain) IBOutlet NSButton *mergeFilesButton;

-(void)setMergeFilesButtonState:(BOOL)yn;

Relevant code for MergeFilesController.m file:

- (IBAction)mergeFiles:(id)sender {

   //Code goes here
}

- (void)setMergeFilesButtonState:(BOOL)yn {

    [mergeFilesButton setHidden:yn];
}

I have another class (called DragDropController) that controls some drag-and-drop functionality for an NSView. From the DragDropController.m file, I want to be able to change the state of the mergeFilesButton based on some stuff that happens from within the DragDropController class.

It is from the DragDropController class that I was trying to call setMergeFilesButtonState.

Was it helpful?

Solution

You should use a controller class. View classes should be used for displaying and hosting controls. Controls should pass interaction details to the controller. The controller should control all of the views.


DragDropController should be generic and not know about the other controller specifically. Instead it should post a notification as it's state changes and other controllers can observe the notifications to determine when updates should be made to the UI.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top