iphone - How to assign didSelectRowAtIndexPath in Tableview cells subview item -
i have 2 problem , totally confuse. please me
1) face 1 problem want assign click listener image view inside of subview , subview in cell of uitableview
.
in tableview cell there 2 image-view want give them click listener , identify them image-view clicked on row etc etc.
if write scrollview.userinteractionenable=yes;
didselectrowatindexpath
not responds. know because of subview. if change scrollview.userinteractionenable=no;
didselectrowatindexpath
code executes. scrollview not scroll horizontal..
what do ? want horizontal scroll plus image-view click listener on both imageview.
** solve click problem crating scrollview sub class**
this customcell class
cellscrollviewclass *scrollview = [[cellscrollviewclass alloc] initwithframe:cgrectmake(0.0,0.0,430,187)]; scrollview.contentsize = cgsizemake(scrollview.frame.size.width * 3,scrollview.frame.size.height); scrollview.scrollenabled=yes; scrollview.userinteractionenabled=yes; (int = 0; < 3; i++) { cgrect frame; frame.origin.x = scrollview.frame.size.width * i; frame.origin.y = 0; frame.size = scrollview.frame.size; if(i==2) // check last item must train engine { uiview *engineview = [[uiview alloc]initwithframe:frame]; uiimageview *engineimageview = [[uiimageview alloc]initwithframe:cgrectmake(-112.5, 6, 430, 180)]; uiimage *image = [uiimage imagenamed:@"backengine.png"]; engineimageview.contentmode = uiviewcontentmodescaleaspectfit; engineimageview.image = image; [engineview addsubview:engineimageview]; [scrollview addsubview:engineview]; // add 3rd imageview train engine end of scrollview } else{ // not equal 2 must wagon of train. uiview *wagon = [[uiview alloc]initwithframe:frame]; uicolor *background = [[uicolor alloc] initwithpatternimage:[uiimage imagenamed:@"wagon.png"]]; wagon.backgroundcolor = background; uiview *videoviewcontainer = [[uiview alloc]initwithframe:cgrectmake(20, 40, 220 , 200)]; uiimageview *videoimageview = [[uiimageview alloc]initwithframe:cgrectmake(0,0, 220, 100)]; uiimage *bgimage = [uiimage imagenamed:@"video.png"]; videoimageview.image = bgimage; videoviewcontainer.contentmode = uiviewcontentmodeleft; // set video image view left hand side of wagon uiview videoimageview.tag=2; [videoviewcontainer addsubview:videoimageview]; uitapgesturerecognizer *singletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(singletapgesturecaptured:)]; [videoimageview addgesturerecognizer:singletap]; [videoimageview setmultipletouchenabled:yes]; [videoimageview setuserinteractionenabled:yes]; uiview *textuiview = [[uiview alloc]initwithframe:cgrectmake(238,28, 150 , 187)]; textuiview.contentmode = uiviewcontentmoderight; uilabel * label = [[uilabel alloc]initwithframe:cgrectmake(28,10, 150 , 87)]; label.text=@"this testing text ios app check line aligned or not , check video image , nested views uiviews"; label.backgroundcolor = [uicolor clearcolor]; label.textcolor=[uicolor redcolor]; label.numberoflines = 4; [textuiview addsubview:label]; [wagon addsubview:textuiview]; [wagon addsubview:videoviewcontainer]; [scrollview addsubview:wagon]; [self.contentview addsubview:scrollview]; } } } return self; } - (void)singletapgesturecaptured:(uitapgesturerecognizer *)gesture { nslog(@"touch event on view %d",gesture.view.tag); }
and created scrollview subclass this..
@implementation cellscrollviewclass - (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code nslog(@"you in scrollview"); } return self; }
is 1 right method of implementation?
any appreciated . thank in advance.
use uitapgesturerecognizer
. create , attach tap gesture recogniser each image view when create it. set tag of image view when create can identify 1 on cell.
when callback recogniser can tag by:
recogniser.view.tag
and can table view cell looping on superview until find table view cell class:
uiview *superview = recogniser.view.superview; while (superview != nil && ![superview iskindofclass:[uitableviewcell class]]) { superview = superview.superview; }
then can index path table view using
[tableview indexpathforcell:superview];