ios - Get position of cell or text field in this cell -


i have split view controller: view & tableview. in table view have custom cells text field. don't know how many cells have, generate automaticly. , i'm trying scroll textfield, when becomefirstresponder. i've tried this:

-(void) textfielddidbeginediting:(uitextfield *)textfield {     cgpoint focusontextfield = cgpointmake(0, 300 + textfield.frame.origin.y);     [scroller setcontentoffset: focusontextfield animated: yes]; } 

300px - start position of tableview. seems alright, textfield.frame.origin.y equal 0 (like , bounds.origin.y btw).

i thought can solve problem if position of cell, textfield active, , replace textfield.frame.origin.y on cell.frame.origin.y or this.

sorry english, hope understand did & want do. :-)

===========================================================================

thank you, guys. forgot tableviews scroll disabled. follow advices , code examples , solve that:

- (uitableviewcell *)cellwithsubview:(uiview *)subview {      while (subview && ![subview iskindofclass:[uitableviewcell self]])         subview = subview.superview;     return (uitableviewcell *)subview; }  - (void)textfielddidbeginediting:(uitextfield *)textfield {     uitableviewcell *activecell = [self cellwithsubview:textfield];      float offsetvaluey = 200 + activecell.origin.y;     cgpoint focusontextfield = cgpointmake(0, offsetvaluey);     [scroller setcontentoffset:focusontextfield animated:yes]; } 

and know what? it's working! :-) create new problem. when begin editing textfield, scroller @ first jump on top, , going correct position. when write [scroller setcontentoffset:focusontextfield animated:no]; , problem disappear, there no smooth move of scroller. , bad me :-) how can solve it? :-)

here's how scroll cell containing text field ...

// find cell containing subview.  works independently of how cells // have been constructed.  - (uitableviewcell *)cellwithsubview:(uiview *)subview {      while (subview && ![subview iskindofclass:[uitableviewcell self]])         subview = subview.superview;     return (uitableviewcell *)subview; } 

your idea correct trigger action when editing begins. using cell...

- (void)textfielddidbeginediting:(uitextfield *)textfield {      // find cell containing text field     uitableviewcell *cell = [self cellwithsubview:textfield];      // scroll using cell's index path target     nsindexpath *indexpath = [self.tableview indexpathforcell:cell];     [self.tableview scrolltorowatindexpath:indexpath atscrollposition:uitableviewscrollpositiontop animated:yes]; } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -