ios - Need help adding data to a TableView -


my first view controller has tableview.

on second view controller, user input data , click button.

i want button add data table view, can not figure out how this.

var textarray: nsmutablearray! = nsmutablearray()  @iboutlet weak var tableview: uitableview!  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return self.textarray.count }  func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     return uitableviewcell() }    @iboutlet weak var adddata: uibutton!  @ibaction func adddata(sender: anyobject) {      self.textarray.addobject(textfield.text)     self.tableview.reloaddata()  } 

it brings error reloaddata line of code.

presumably code have quoted in second view controller. ibaction in view controller can't reload self.tableview because table in first view controller.

to looking there literally dozens of approaches each pluses , minuses. maybe easiest implement is:

  1. creating public variable in second view controller called textarray.
  2. set public variable in prepareforsegue data source of table in first view controller.
  3. add string variable in ibaction of second view controller self.textarray.addobject(textfield.text).
  4. add self.tableview.reloaddata() line viewwillappear function of first view controller.

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -