Sunday 15 May 2011

ios - MVC: should i add and implement touch gestures in the View Controller or my custom subclass of UIView -



ios - MVC: should i add and implement touch gestures in the View Controller or my custom subclass of UIView -

i have custom subclass of uiview, called productcardview, pretty simple , has uiimageviews , uilabels it's subviews. add together subviews , set them - (void)drawrect:(cgrect)rect method , sits nicely.

in view controller info remote server , populate productcardviews should seen. purpose when user taps on each of these cards programme goes target url(a nsurl property of each card).

the question is according basics of mvc, should add together uitapgesturerecognizer view, within implementation of productcardview or in view controller? if add together in view controller, set appropriate code in viewdidload method, create instances of cards, in case should implement in view itself, where should set code? (in -(void)drawrect:(cgrect)rect?)

whether tap on card or on view controller should loading url view controller.

so, means either...

card feels tap , calls function in delegate (the view controller) loads url.

or

tap gesture recogniser (in view controller) gets tap card , open url.

if card command used in several places (or if have several on screen) might improve making productcardview subclass of uicontrol instead of uiview. (uibutton, uislider, etc... subclasses of uicontrol).

there isn't much need alter can like...

[productcardview addtarget:self action:@selector(cardtapped:) event:uitouchupinside];

just button.

you handle touch in card view , trigger action event uitouchupinside.

ios objective-c uiview uiviewcontroller uigesturerecognizer

No comments:

Post a Comment