0

On the click of a button I load my tableview like so...

class MyViewController: UIViewController {

  @IBOutlet weak var tableview: UITableView! 
  var tableConfig : TableViewConfig<Company, CompanyCell>?

  private var tabledata = [Company]() {
    didSet {
      tableConfig?.items = tabledata
    }
  }

  // MARK: - View Life Cycle
  override func viewDidLoad() {
    super.viewDidLoad()   
    configureTableView()    
  }

  private func configureTableView() {
    let cellIdentifier = String(describing: CompanyCell.self)
    tableview.register(UINib(nibName: cellIdentifier, bundle: Bundle.main), forCellReuseIdentifier: cellIdentifier)

    tableConfig = TableViewConfig<Company, CompanyCell>(tableview, items: tabledata, cellIdentifier: cellIdentifier, configClosure: { object, cell in
      cell.configureCompany(object)
    })

    tableConfig?.selectedRow { indexPath in
      // Call Delegate Action
      if let index = indexPath?.row {
        let company = self.tabledata[index]
        self.tabledata[index] = company
        self.tableConfig?.items = self.tabledata
        self.tableview.reloadRows(at: [indexPath!], with: .automatic)
      }
    }
    tableview.dataSource = tableConfig
    tableview.delegate = tableConfig
  }
}

Here, in this line...var tableConfig : TableViewConfig<Company, CompanyCell>?, the Company and CompanyCell are names of the model and UITableViewCell respectively.

What I want is that on the click of the button, while loading MyViewController (i.e. the viewcontroller given above), I want to pass the model name and the tableviewcell name. But how to pass the model name from one viewcontroller to the other, I can't figure out.

I have tried this, this and this link. But it didn't help.

Hope somebody can help...

  • it isn't a duplicate @Joakim Danielson ..your link deals with just passing normal data around..but I have to pass a model from 1 view to the other which cannot be done as suggested in the link u provided.. –  May 29 '19 at 13:30
  • 1
    Sometimes you write model and sometimes you write model name, care to explain what you mean and what is so special about your data that it can't be passed the normal way? Hmm, I read it again and wonder if you mean the type of the class struct like `Company.self`? – Joakim Danielson May 29 '19 at 13:32

1 Answers1

-1

I'm not sure if I've understood your question. Maybe what you're trying to achieve is something like this:

class MyViewController<Company, CompanyCell>: UIViewController
{
    ...
}

let myViewController = MyViewController<MyCompany, MyCompanyCell>()
Marco
  • 1,572
  • 1
  • 10
  • 21