0

In Swift, I have a tableview that dynamically creates custom cells. Every single one of these cells has a textfield. How do I call all of the textfields user inputs? My intention is to create a button that appends all of them to an array. I know how to do everything except call the cell data and it needs to be dynamic. I was thinking of the following below. Am I on the right track? Thanks

//Psuedo
FOR LOOP {
    array.append(tbl.cellForRowAtIndexPath(<#indexPath: NSIndexPath#>).SOME_SWIFT_METHOD())
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • You're a bit off since you're using some pseudo code with no real code equivalent, i.e. .SOME_SWIFT_METHOD() – Lyndsey Scott Mar 29 '15 at 22:59
  • Here's an Objective-C answer to this question that should help you out: http://stackoverflow.com/a/6914277/2274694 – Lyndsey Scott Mar 29 '15 at 23:01
  • 1
    I don't know what you mean by "call all of the textfields user inputs" or "call the cell data", but you shouldn't try to get data from a cell. You should make the controller the delegate of the text fields, and implement one or more of the text field delegate methods. When the user finishes editing, you should update your model with the string entered into the text field. This will happen as soon as the user finishes the edit, so there's no need for a button to upload the values to an array. – rdelmar Mar 29 '15 at 23:01
  • The purpose of my pseudo is to show that I am looking at using cellForRowAtIndexPath, which I don't know how to use and I don't know if it is the correct way to go about accessing all the cells. I've looked all over the internet and this topic hasn't been covered anywhere. – user3704498 Mar 29 '15 at 23:01
  • @user3704498 It's been covered in the answer I linked to: http://stackoverflow.com/a/6914277/2274694 – Lyndsey Scott Mar 29 '15 at 23:02

0 Answers0