cocoa touch - Getting touches for a view with subview -


i want have top view (subclass of uiview), catches touches using

- (void) touchesbegan:(nsset *)touches withevent:(uievent *)event - (void) touchesmoved:(nsset *)touches withevent:(uievent *)event ... 

.h

@interface xview : uiview<uitableviewdatasource, uitableviewdelegate> @property (nonatomic, strong) uitableview * tableview; @end 

this works fine, if view empty, insert (addsubview) lets uitableview

- (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code self.tableview = [[uitableview alloc] initwithframe:self.frame]; self.tableview.delegate = self; self.tableview.datasource = self; [self addsubview:self.tableview]; } return self; } 

than touch methods inside xview not triggered

you either need subclass uitableview or use uitapgesturerecognizer solve this. i'd go uitapgesturerecognizer.

uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tapcode:)]; [self.tableview addgesturerecognizer:tap]; 

and can handle tap here:

- (void)tapcode:(uitapgesturerecognizer *)recognizer { // code goes here } 

if subclass uitableview, can put touchesbegan:withevent in there.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -