【发布时间】: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<Company, CompanyCell>?,Company 和 CompanyCell 分别是模型和 UITableViewCell 的名称。
我想要的是在单击按钮时,在加载MyViewController(即上面给出的视图控制器)时,我想传递模型名称和 tableviewcell 名称。但是如何将模型名称从一个视图控制器传递到另一个,我不知道。
我尝试过this、this 和this 链接。但这没有帮助。
希望有人能帮忙...
【问题讨论】:
-
这不是重复的@Joakim Danielson ..您的链接只处理传递正常数据..但我必须将模型从一个视图传递到另一个视图,这不能按照建议中完成你提供的链接..
-
有时你写模型,有时你写模型名称,想解释一下你的意思以及你的数据有什么特别之处以至于它不能以正常方式传递?嗯,我又读了一遍,想知道你的意思是不是像
Company.self这样的类结构的类型?