iphone - Tap gesture doesn't work after setContentOffset -


i have uitapgesturerecognizer on uitableview. works great until call method scrolltorowatindexpath:atscrollposition:animated:. doesn't work once that's called. doesn't work once call setcontentoffset:. have scroll tableview finger little bit, , tap gesture work. how can work after setting contentoffset or scrolling row?

-(void)viewdidload {     // gesture doesn't work after 'setcontentoffset:'     uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget: self action: @selector(hideshowediting:)];     [tap setcancelstouchesinview: yes];     [tap setdelegate: self];      [self setedittap: tap];     [[self tableview] addgesturerecognizer: tap]; }   -(bool)hideshowediting:(uigesturerecognizer *)gesture {     cgpoint location = [gesture locationinview: [self tableview]];     nsindexpath *ip = [[self tableview] indexpathforrowatpoint: location];     taskcell *cell = (taskcell *)[[self tableview] cellforrowatindexpath: ip];      // no cells expanded, expand 1     if (editingcellrow == -1 && editingcellsection == -1 && ![gesture iskindofclass: [uiswipegesturerecognizer class]]) {          editingcellrow = [ip row];                          // if it's swipe gesture, it's crossout method         editingcellsection = [ip section];          [[self tableview] beginupdates];         [[self tableview] endupdates];          [cell addviewsforediting];          // tap gesture doesn't work if has scroll tableview         [[self tableview] scrolltorowatindexpath: ip atscrollposition: uitableviewscrollpositionnone animated: yes];          return yes;     }     // cell expanded, unexpand other cell     // , expand cell     else if ((editingcellrow != [ip row] || editingcellsection != [ip section]) && ![gesture iskindofclass: [uiswipegesturerecognizer class]]) {          // index path of expanded cell         nsindexpath *expandedip = [nsindexpath indexpathforrow: editingcellrow insection: editingcellsection];         taskcell *expandedcell = (taskcell *)[[self tableview] cellforrowatindexpath: expandedip];          [expandedcell setanimateexpansion: yes];         [cell setanimateexpansion: yes];          // store index of new expanded cell         editingcellrow = [ip row];         editingcellsection = [ip section];          [[self tableview] beginupdates];         [[self tableview] endupdates];          [expandedcell removeviewsforediting];          [[self tableview] scrolltorowatindexpath: ip atscrollposition: uitableviewscrollpositionnone animated: yes];          [cell addviewsforediting];          return yes;     }     // tapped expanded cell, unexpand     else if (editingcellrow == [ip row] && editingcellsection == [ip section]) {         [cell setanimateexpansion: yes];          editingcellrow = -1;         editingcellsection = -1;          [[self tableview] beginupdates];         [[self tableview] endupdates];          [cell removeviewsforediting];          return yes;     }      return no; } 

i don't understand why doesn't you. i've tested , works. tableviewcontroller rootviewcontroller of delegate's window.rootviewcontroller nothing special here, idea have navbar put button in it.

this tableviewcontroller.h :

#import <uikit/uikit.h>  @interface viewcontroller : uitableviewcontroller <uigesturerecognizerdelegate>  // scrolling method - (void)move:(id)sender;  // method triggered tap - (void)tapit:(id)sender;  @end 

this tableviewcontroller.m (an extract of main part):

- (void)viewdidload {     [super viewdidload];      // add bar button call scrolling method     uibarbuttonitem *rightbtn = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemaction target:self action:@selector(move:)];     self.navigationitem.rightbarbuttonitem = rightbtn;      //add tap gesture     uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tapit:)];     [tap setcancelstouchesinview:yes];     [tap setdelegate:self];     tap.numberoftouchesrequired = 1;     tap.numberoftapsrequired = 1;     [[self tableview] addgesturerecognizer:tap]; }  #pragma mark - table view data source - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     // return number of sections.     return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     // return number of rows in section.     return 20; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"cell";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }      // configure cell...     cell.textlabel.text = [nsstring stringwithformat:@"item %i", indexpath.row];      return cell; }  // scrolling method - (void)move:(id)sender {     nslog(@"scroll");     //scroll 17th row exemple     [self.tableview scrolltorowatindexpath:[nsindexpath indexpathforrow:17 insection:0] atscrollposition:uitableviewscrollpositionbottom animated:yes]; }  // method triggered tap gesture - (void)tapit:(id)sender {     nslog(@"tap it"); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -