xcode - How to let the controller handle a gesture added in the view? iOS -


i got card draw custom view. want add swipe gesture every card flip , being chosen. since every card view needs gesture, choose add gesture in method initwithframe: of view. however,i want leave controller handle gesture when recognized because choosing card method in controller. here code:

[self addgesturerecognizer:[[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(swipe:)]]; 

actually need target my controller, want call method named swipe in controller. target self leave handling of gesture view itself.

maybe can't controller replace target.can tell correct way solve problem?

your view should not know controller is. (this increase coupling , decrease cohesion, bad.)

a common solution problem view declare delegate protocol. view controller can set view's delegate. view's swipe: method call delegate method.

for example code, see this question.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -