ios - scroll table view top when selecting an textfield -


i have uitableview custom cell uitextfield , buttons on ,my issue when ever user selects textfields in bottom keybord hiding textfield , tried scroll uitableview seeing answers in stackoverflow. not scrolling can 1 me in finding out mistake made me please.i have written code scrolling in textfielddidbeginediting: method .textfielddidbeginediting: firing , executing code in not scrolling up.

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section; {    // nslog(@"no of rows:%d",[contents count]); return [contents count];  }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath; {  static nsstring *cellidentifier = @"cell";  // try retrieve table view now-unused cell given identifier. cell = (uploadcustomcell *)[tableview dequeuereusablecellwithidentifier:@"uploadcustomcell"]; if (cell == nil) {     cell = [[uploadcustomcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:@"uploadcustomcell"];     nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"uploadcustomcell"                                                         owner:self options:nil];           cell = [nib objectatindex:0]; }   savebtnccell.hidden = yes; cell.textnamefield.hidden = yes;  [cell setselectionstyle:uitableviewcellselectionstylenone]; [cell.defaultswitch setenabled:no]; dictionarycontents = [contents objectatindex:indexpath.row]; cell .namelabelcell.text   = [dictionarycontents valueforkey:@"videoname"]; cell.username.text = [dictionarycontents valueforkey:@"user"]; cell.thumbimg.image = [arrayimage objectatindex:indexpath.row];    nsstring *defaultvideo = [dictionarycontents valueforkey:@"defaultvideo"]; if ([defaultvideo isequal: @"1"]) {     [defaultswitche seton:yes animated:yes];  } else{     [defaultswitche seton:no animated:yes]; }   [cell.defaultswitch addtarget:self action:@selector(setstate:)forcontrolevents:uicontroleventvaluechanged]; videonametextfield.hidden = yes; return cell; }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { return 207; }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{  //    selectedrow=indexpath.row; indexpathtest = indexpath.row; [tabelview1 reloaddata]; nsmutablearray *dictionary = [contents objectatindex:indexpath.row]; guid = [dictionary valueforkey:@"guid"]; detailsvehimg.image = [arrayimage objectatindex:indexpath.row];;   }   - (bool)tableview:(uitableview *)tableview caneditrowatindexpath:(nsindexpath  *)indexpath  {   return yes;  }   - (uitableviewcelleditingstyle)tableview:(uitableview *)tableview editingstyleforrowatindexpath:(nsindexpath *)indexpath; {   return  uitableviewcelleditingstyledelete;  }   - (void)textfielddidbeginediting:(uitextfield *)textfield {    [self.tabelview1 scrolltorowatindexpath:1 atscrollposition:uitableviewscrollpositiontop animated:yes];   } 

you have reload tableview before scrolling it. have added 1 line of code in textfielddidbeginediting. please try this.

- (void)textfielddidbeginediting:(uitextfield *)textfield  {     [self.tabelview1 reloaddata];      nsarray *indexpathsforvisiblerows = [self.tabelview1 indexpathsforvisiblerows];     nsindexpath *selectedindexpath = [indexpathsforvisiblerows objectatindex:(indexpathsforvisiblerows.count/2)];     [self.tabelview1 scrolltorowatindexpath:selectedindexpath atscrollposition:uitableviewscrollpositiontop animated:no];  } 

good luck


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -