将模型名称传递给ViewController

时间:2019-05-29 12:57:50

标签: ios swift tableview

按一下按钮,我像这样加载表格视图...

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
  }
}

这里,在此行... var tableConfig : TableViewConfig<Company, CompanyCell>?中,CompanyCompanyCell分别是模型的名称和UITableViewCell。

我想要的是单击按钮,同时加载MyViewController(即上面给出的视图控制器),我想传递模型名称和tableviewcell名称。但是我不知道如何将模型名称从一个视图控制器传递到另一个。

我尝试了thisthisthis链接。但这没有帮助。

希望有人可以帮忙...

1 个答案:

答案 0 :(得分:-1)

我不确定我是否理解您的问题。也许您想要达到的目标是这样的:

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

let myViewController = MyViewController<MyCompany, MyCompanyCell>()
相关问题