design question concerning model changes and notification - cocoa
I have class A which is a NSView which contains a remove method, this method removes items from an array that is pulled from a Model class.
Class B is also an NSView, it draws some stuff depending on this Model class.
My issue is that when class A modifies the model collection Class B is not notified of the开发者_如何学运维 change and its view is not updated correctly.
I thought I could register Class B to the notification center but I dont think Im doing right.... thanks for any help.
Without seeing your code it's hard to figure out what the best solution is. I think the best way (depending on the complexity of your app) would be to have a controller class between your model and views that would update the model and alert the views to the change in a single method. This is sort of an Observer pattern. Alternatively, you could have an update method in the model that calls a method in Class B to let it know that there's a model update. This would require the model to hold pointers to your instances of Class A and Class B.
精彩评论