i have 2 views: view tag 1 , view tag 2. each view has 2 gesture recognizers.
cgrect temprect=cgrectmake(0, 0, 100, 100); (int i=1; i<=2; i++) { uiview *tempview=[[uiview alloc] initwithframe:temprect]; uiimageview *tempimageview=[[uiimageview alloc]initwithframe:temprect]; tempimageview.image=[uiimage imagenamed:[nsstring stringwithformat:@"%@%d%@",@"image_",i,@".png"]]; uiswipegesturerecognizer *temprecognizer = [[uiswipegesturerecognizer alloc] init]; [temprecognizer performselector:@selector(swiperight:) withobject:[nsnumber numberwithint:i]]; [temprecognizer setdirection:(uiswipegesturerecognizerdirectionright)]; [tempview addgesturerecognizer:temprecognizer]; [tempview addsubview:tempimageview]; tempview.tag=i; [self.view addsubview:tempview]; }
i have method: swiperight manages swipe....
-(void)swiperight:(nsnumber*)mytag{ int myprogr = [mytag intvalue]; }
which correct way pass tag? code got error:
[uiswipegesturerecognizer swiperight:]: unrecognized selector sent instance...
set view tag before
[tempview settag:i]; uiswipegesturerecognizer *swiperight = [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(callyourmethod:)]; swiperight.direction = uiswipegesturerecognizerdirectionright; [tempview addgesturerecognizer:swiperight]; - (void)callyourmethod:(uiswipegesturerecognizer *)recognizer { if (recognizer.direction == uiswipegesturerecognizerdirectionright) { int tagvalue = recognizer.view.tag; nslog(@"down"); } }
Comments
Post a Comment