0

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.

4

1 回答 1

0

您应该使用控制器类。视图类应该用于显示和托管控件。控件应将交互详细信息传递给控制器​​。控制器应该控制所有的视图。


DragDropController应该是通用的,并且不具体了解其他控制器。相反,它应该在状态更改时发布通知,并且其他控制器可以观察通知以确定何时应该对 UI 进行更新。

于 2013-08-26T17:43:57.657 回答