ios - How to use scrollRectToVisible:animated? -


i have tableview , in 1 of rows have horizontal scrollview , images(images in different view of row), in horizontal scrollview have added few buttons (10 buttons). when user clicks on button scrollview call reloaddata. because call reloaddata horizontal scrollview reloads again new image data. want if user scrolls end , clicked last button scrollview, user should able see selected button not first one. don't know how can use scrollrecttovisible:animated make happen.

here code scrollview , adding buttons on it.

-(void)addcolorfiltersonview:(uiview *)colorview{            if (_colorfilterview) {         [_colorfilterview removefromsuperview];     }      self.colorfilterview = [[uiscrollview alloc] initwithframe:colorview.bounds];     [_colorfilterview setautoresizingmask:uiviewautoresizingflexiblewidth|uiviewautoresizingflexibleheight];     [_colorfilterview setbackgroundcolor:samergb(238)];     [_colorfilterview setshowshorizontalscrollindicator:no];      int addedcount = 0;     int i=0;      cgfloat x = 10, y = 5;      if ([_colorfilters count] < 1) {         return;     }      (i=0; i<[_colorfilters count] - 1; i++) {          id item = [_colorfilters objectatindex:i];          if ([item iskindofclass:[nsstring class]]){              if ([self.prodvipdictionary.pdcolor isequaltostring:(nsstring*)item] && != 0) {                 continue;             }              nsinteger itemscount = [[_colorfilters objectatindex:i+1] integervalue];              if (itemscount  <= 0) {                 break;             }              tttattributedlabel *itemlabel = [[tttattributedlabel alloc] initwithframe:cgrectzero];             [itemlabel setnumberoflines:1];             [itemlabel settextalignment:nstextalignmentcenter];             [itemlabel setfont:[uifont systemfontofsize:14]];              if ([_selectedcolor isequaltostring:(nsstring*)item])                 [itemlabel settextcolor:[uicolor whitecolor]];              [itemlabel settext:[(nsstring*)item capitalizedstring]];             [itemlabel setbackgroundcolor:samergb(255)];             itemlabel.layer.borderwidth = 1;             itemlabel.layer.maskstobounds = yes;             itemlabel.layer.cornerradius = 10;             itemlabel.layer.bordercolor = samergb(210).cgcolor;             [itemlabel sizetofit];             [_colorfilterview addsubview:itemlabel];              cgrect itemframe = itemlabel.frame;             itemframe.size.width += 20;             [itemlabel setframe:itemframe];              uibutton *optionbtn = [[uibutton alloc] initwithframe:cgrectmake(x, y, itemlabel.frame.size.width + 6, 26)];             [optionbtn settag:[_colorfilters indexofobject:item]];             [optionbtn addtarget:self action:@selector(optioncolorclicked:) forcontrolevents:uicontroleventtouchupinside];              [_colorfilterview addsubview:optionbtn];              [itemlabel setframe:optionbtn.frame];              if ([_selectedcolor isequaltostring:(nsstring*)item]) {                 [optionbtn setenabled:no];                 [itemlabel setbackgroundcolor:[lrutils lrgreencolor]];             }              addedcount ++;              x += optionbtn.frame.size.width+5;              if (addedcount >= 20) {                 break;             }          }else{             continue;         }     }      [_colorfilterview setcontentsize:cgsizemake((x + 10),colorview.frame.size.height)];     [colorview addsubview:_colorfilterview]; } 

instead of calling reloaddata, call method on table view:

- (void)reloadrowsatindexpaths:(nsarray *)indexpaths withrowanimation:(uitableviewrowanimation)animation

you need create nsarray containing of indexpaths in table view except row scroll view , buttons. way, scroll view wouldn't reset.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -