cocoa touch - how to get uiview to talk to controller -


i'm relatively new objective-c , cocoa... i've been trying understand how correctly implement mvc pattern in cocoa/cocoa touch long time now... understand idea behind it; makes complete sense conceptually: model holds data, view user sees , can interact with, , controller acts bridge between two. view can't talk model, model can't talk view. got it.

what doesn't make sense me how use mvc efficiently… if user can interact view, , interact (i.e. iphone app, user clicks/drags within subclass of uiview, triggering "touchesbegan" , "touchesmoved" methods, etc.), how view communicate these events controller?

i've looked @ countless examples , forums online, have yet find simplified all-purpose way of achieving this… know how communicate controller through buttons, sliders, , other things can connect outlet, things don't have target-action mechanism, what's best way it?

thanks in advance suggestions regarding do, or look.

  1. the standard way in cocoa delegate pattern (cf. uitableviewdelegate). view class declare delegate protocol , controller sets view's delegate. view calls 1 of delegate methods defined whenever wants communicate controller.

  2. an alternative implement target-action mechanism view yourself. more or less free if subclass uicontrol (just call sendactionsforcontrolevents:) quite easy implement system works same way custom class.

  3. (edit: suppose third way have controller observe properties of view (with kvo). wouldn't work communicate touch events feasible way if want notify controller state change or that.)


Comments