Update UI from another Class Method - Cocoa

前端 未结 3 973
清歌不尽
清歌不尽 2021-01-14 14:09

I would like to update the UI in my application from the AppDelegate, but whenever I call it as so:

Controller *object = [[Controller alloc] init];
[object          


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 14:50

    When you write [[Controller alloc] init], you are not accessing the Controller object that is in your nib. You are creating a new Controller object that is unconnected to anything else in your application.

    Remember, every Controller object is not the same any more than every NSArray is the same. Just because you made one Controller in your nib that's connected to an NSTextField does not mean some random Controller that you just created shares that controller's connections.

    What you need to do is give the delegate a reference to the Controller that's in the nib.

提交回复
热议问题