Objective-C/Cocoa: Proper design for delegates and controllers

前端 未结 4 2028
余生分开走
余生分开走 2020-12-28 23:11

Consider the following common situation:

You have some MainView in your Cocoa application, loaded from a NIB, which is controlled by a MainViewCon

4条回答
  •  悲哀的现实
    2020-12-29 00:14

    We implemented a tricky "Data"-object which controlls pretty much everything. It checks if there are changes and keeps all globals updated.

    When creating new instances I refer to the Data class like this:

    [[Button alloc] initWithData:data]];
    

    Where data is the singelton Data-class. Now we can check if there are changes needed to react on.

    I admit, it still requires referencing like you described though. There doesn't seem to be a simple parent reference imbedded.

提交回复
热议问题