ios - How do I send the data from a custom picker to a table cell in a second tableview controller? -


this question has answer here:

i new swift , trying learn write first simple app. have storyboard custom picker on main viewcontroller , need populate table cells in second tableviewcontroller picker selections first. basically, user make selection picker in the first view, click "add" button take selection , add table in second view. can follow same process additional selections. use list or else i'm not married using table.

can lead me right direction on how this? please keep in mind new , trying learn here. can't seem find far me. thanks!

you need fetch data of selected row in custom uipickerview , send uitableviewcontroller, i.e.

1. fetching , passing data

var tablecontroller: tableviewcontroller?  @ibaction func additem(sender: uibutton) {     if let tablecontroller = self.tablecontroller     {         tablecontroller.items.append(items[self.picker.selectedrow(incomponent: 0)])         tablecontroller.tableview.reloaddata()         self.navigationcontroller?.pushviewcontroller(tablecontroller, animated: true)     } } 

2. uitableviewcontroller

class tableviewcontroller: uitableviewcontroller {     var items = [string]()      override func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int     {         return items.count     }      override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {         let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath)         cell.textlabel?.text = items[indexpath.row]         return cell     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -