ios - Swift: TableView scroll to position -


maybe wrong way of doing please show me correct way if wrong. have tableview on scrollview. cells have textfield onclick shows keyboard. problem having cells @ bottom of scroll view end getting stuck behind keyboard.

// build tableview self.shippingtableview = uitableview(frame: cgrectmake(0, 5, self.view.frame.width, cgfloat(tableviewheight))) self.shippingtableview.delegate = self self.shippingtableview.datasource = self self.shippingtableview.scrollenabled = true self.scrollview.addsubview(self.shippingtableview)  // create delegate methods // know i'm not reusing cells yet update later. func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = uitableviewcell()     cell.accessorytype = uitableviewcellaccessorytype.none      let textfield = uitextfield(frame: cgrectmake(10, 0, cell.frame.width, cell.frame.height))     textfield.delegate = self     cell.contentview.addsubview(textfield)     return cell } 

now above code have view on page , if select item, keyboard shows cell behind. created delegate method , tried following. added print line method know getting called.

func textfielddidbeginediting(textfield: uitextfield) {     let indexpath = nsindexpath(foritem: textfield.tag, insection: 0)      // tried each of following separatly, nothing moves.     self.shippingtableview.scrolltorowatindexpath(indexpath, atscrollposition: uitableviewscrollposition.top, animated: true)     self.shippingtableview.scrolltonearestselectedrowatscrollposition(uitableviewscrollposition.middle, animated: true) } 

i guessed problem because had tableview within scrollview tried changing standard view , had same problem.

surely correct answer not scroll manually?

first don't add uitableview in uiscrollview. download tpkeyboardavoiding make tpkeyboardavoidingtableview super class of tableview. , don't have worry scroll tableview manually, tpkeyboard handle automatically.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -