Ios 将模型名称传递给viewcontroller
点击一个按钮,我就可以像这样加载我的tableviewIos 将模型名称传递给viewcontroller,ios,swift,tableview,Ios,Swift,Tableview,点击一个按钮,我就可以像这样加载我的tableview class MyViewController: UIViewController { @IBOutlet weak var tableview: UITableView! var tableConfig : TableViewConfig<Company, CompanyCell>? private var tabledata = [Company]() { didSet { tableCo
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
}
}
类MyViewController:UIViewController{
@IBVAR表格视图:UITableView!
var tableConfig:TableViewConfig?
私有变量tabledata=[公司](){
迪塞特{
tableConfig?.items=tabledata
}
}
//MARK:-查看生命周期
重写func viewDidLoad(){
super.viewDidLoad()
configureTableView()
}
私有函数configureTableView(){
让cellIdentifier=String(描述:CompanyCell.self)
register(UINib(nibName:cellIdentifier,bundle:bundle.main),forCellReuseIdentifier:cellIdentifier)
tableConfig=TableViewConfig(tableview,项:tabledata,cellIdentifier:cellIdentifier,configClosure:{object,中的单元格
cell.configureCompany(对象)
})
tableConfig?.selectedRow{indexPath在
//调用委托操作
如果let index=indexath?.row{
let company=self.tabledata[索引]
self.tabledata[索引]=公司
self.tableConfig?.items=self.tabledata
self.tableview.reloadRows(位于:[indexPath!],带:.automatic)
}
}
tableview.dataSource=tableConfig
tableview.delegate=tableConfig
}
}
在这一行中,var tableConfig:TableViewConfig?
,Company
和CompanyCell
分别是model和UITableViewCell的名称
我想要的是,在加载MyViewController
(即上面给出的viewcontroller)时,单击按钮,我想要传递模型名称和tableviewcell名称。但是如何将模型名称从一个viewcontroller传递到另一个,我不知道
我已经试过了,链接。但这没用
希望有人能帮忙……我不确定我是否理解你的问题。也许你想要达到的目标是这样的:
class MyViewController<Company, CompanyCell>: UIViewController
{
...
}
let myViewController = MyViewController<MyCompany, MyCompanyCell>()
类MyViewController:UIViewController
{
...
}
让myViewController=myViewController()
我基本上想把我的模型从一个类传递到另一个类@marcourry,但我仍然不清楚你的问题它不是一个重复的@Joakim Danielson..你的链接只是传递普通数据..但我必须将一个模型从一个视图传递到另一个视图,这无法按照你提供的链接中的建议完成..有时你写模型,有时你写模型名称,你想解释一下你的意思吗?你的数据有什么特别之处,以至于不能以正常的方式传递?嗯,我又读了一遍,不知道你指的是类结构的类型,比如Company.self
?