【问题标题】:Pass model name to a viewcontroller [duplicate]将模型名称传递给视图控制器 [重复]
【发布时间】:2019-05-29 21:51:52
【问题描述】:

单击按钮后,我会像这样加载我的表格视图...

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&lt;Company, CompanyCell&gt;?CompanyCompanyCell 分别是模型和 UITableViewCell 的名称。

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

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

希望有人能帮忙...

【问题讨论】:

  • 这不是重复的@Joakim Danielson ..您的链接只处理传递正常数据..但我必须将模型从一个视图传递到另一个视图,这不能按照建议中完成你提供的链接..
  • 有时你写模型,有时你写模型名称,想解释一下你的意思以及你的数据有什么特别之处以至于它不能以正常方式传递?嗯,我又读了一遍,想知道你的意思是不是像Company.self这样的类结构的类型?

标签: ios swift tableview


【解决方案1】:

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

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

let myViewController = MyViewController<MyCompany, MyCompanyCell>()

【讨论】:

  • 我基本上想将我的模型从一个班级传递给另一个班级@Marco
  • 对不起,我还不清楚你的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-26
  • 1970-01-01
  • 1970-01-01
  • 2014-07-03
  • 1970-01-01
相关资源
最近更新 更多