ios - How to call didSelectRowAtIndexPath from subclassed UITableViewCell -
i have uitableview using show data requiers me have wider cell iphone screenwidth.
because of have created subclassed uitableviewcell contains subclassed uiscrollview. code looks like.
tableview.h
@property (strong, nonatomic) customcell *cell;
tableview.m
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { celldictionary = [xmlmarray objectatindex:indexpath.row]; static nsstring *cellidentifier = @"cell"; cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[customcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } // configure cell. cell.selectionstyle = uitableviewcellselectionstylegray; cell.itemsdictionary = celldictionary; cell.currentindex = indexpath; celldictionary = nil; [cell drawcell]; return cell; }
in above method can see calling custom uitableviewcell have created.
customcell.h
@property (strong, nonatomic) nsdictionary *itemsdictionary; @property (strong, nonatomic) myscrollview *scrollcell; @property (strong, nonatomic) nsindexpath *currentindex; - (void)drawcell;
customcell.m
- (void)drawcell { scrollcell = [[myscrollview alloc] init]; scrollcell.itemsdictionary = itemsdictionary; [scrollcell drawcell]; scrollcell.backgroundcolor = [uicolor whitecolor]; scrollcell.frame = cgrectmake(0.0, 0.0, screenwidth, 45.0); [[self contentview] addsubview:scrollcell]; }
in above drawcell method calling custom scrollview
myscrollview.m
- (void)drawcell { bggray = no; fnamestring = [[uilabel alloc] init]; fnamestring.backgroundcolor = [uicolor clearcolor]; fnamestring.frame = cgrectmake(15.0, 0.5, 70.0, 40.0); fnamestring.text = [itemsdictionary objectforkey:@"fname"]; lnamestring = [[uilabel alloc] init]; lnamestring.backgroundcolor = [uicolor clearcolor]; lnamestring.frame = cgrectmake(105.0, 0.5, 95.0, 40.0); lnamestring.text = [itemsdictionary objectforkey:@"lname"]; addressstring = [[uilabel alloc] init]; addressstring.backgroundcolor = [uicolor clearcolor]; addressstring.frame = cgrectmake(220.0, 10.5, addressstring.frame.size.width, 50.0); addressstring.text = [nsstring stringwithformat:@"address: %@: %@",[itemsdictionary objectforkey:@"anumber"] ,[itemsdictionary objectforkey:@"astring"]]; [addressstring sizetofit]; [self setcontentsize:(cgsizemake((220.0 + addressstring.frame.size.width)+15, 45.0))]; [self addsubview:fnamestring]; [self addsubview:lnamestring]; [self addsubview:addressstring]; }
the above method draws scrollview passed onto customcell, works fine , displays correctly, below method using detect touch on cusome scroll view in same class method above , looks this.
- (void) touchesended: (nsset *) touches withevent: (uievent *) event { nslog(@"touch scroll"); // if not dragging, send event next responder if (!self.dragging) { // touch detected... //how can call didselectrow tableview? } else { [super touchesended: touches withevent: event]; } }
so question this, how can use touchended method call didselectrowfromindexpath method in original tableview class? or there better way doing?
any appreciated if need more informaiton please let me know , best supply it.. have been working on days , dont know go next appreciated... thanks!
**note, reason have had use these subclasses because uiscrollview covering uitableviewcell selection function.. had subclass scrollview intercept touch event im hoping can call original tableview seleciton method help.
how calling delegate function using following code:
[yourtableview.delegate tableview:tableview didselectrowatindexpath:aindexpath];
in subclassed cell store weak reference tableview , indexpath.
another solution loop through cell's superview until find tableview. has cons though, apple may 1 day change way view hierarchy structured break code did ios6 ios7 wrapping layer around views...
Comments
Post a Comment