[英]TableView data pass into another tableview with same UIVIewController?
我想在第一个表视图上执行didSelectRowAt时,使用相同的viewController将第一个表视图数据传递到第二个表视图中。
var bidCreatedByBankerArray : [BidCreatedByBanker]? = nil
var tableData = [String]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == tableView1{
return (bidCreatedByBankerArray?.count)!
}else{
return (tableData.count)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (tableView == self.tableView1) {
let cell = tableView1.dequeueReusableCell(withIdentifier: "NumberOfBidsForBorrowerTableViewCell1ID") as? NumberOfBidsForBorrowerTableViewCell1
let bidCreatedByBankerData = bidCreatedByBankerArray?[indexPath.row]
cell?.projectDescriptionLabel.text = bidCreatedByBankerData?.projectDescription
return cell!
}else {
let cell = tableView1.dequeueReusableCell(withIdentifier: "NumberOfBidsForBorrowerTableViewCell2ID") as? NumberOfBidsForBorrowerTableViewCell2
let bidCreatedByBankerData = tableData[indexPath.row]
return cell!
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as? NumberOfBidsForBorrowerTableViewCell2
}
对我来说,单击第一个表格视图时显示的是空的详细信息。
提前致谢
您的问题似乎还不清楚。 但是我在这里有一些假设:
在视图之间传递数据的意思是将其与tableview的单元格链接,因为这是所有数据的放置位置或假定它位于您的单元格类对象中。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) as? NumberOfBidsForBorrowerTableViewCell2 // getting cell model object from controller instance array let bankerBid = bidCreatedByBankerArray?[indexPath.row] // assuming your data is in cell let data = cell?.dataNeeded // updating second table data tableData[indexPath.row] = bankerBid if tableView != tableView1 { tableView.reloadData() } }
如果这不是您要在下方发表评论的地方,我们很乐意为您提供帮助!
var bidCreatedByBankerArray : [BidCreatedByBanker] = [BidCreatedByBanker]()
var tableData : [BidCreatedByBanker] = [BidCreatedByBanker]()
@IBOutlet weak var tableView1: UITableView!
@IBOutlet weak var tableView2: UITableView!
extension NumberOfBidForBorrowerViewController : UITableViewDelegate, UITableViewDataSource{
//MARK: - TableView
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == tableView1{
return (bidCreatedByBankerArray.count)
}else{
return (tableData.count)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (tableView == self.tableView1) {
let cell = tableView1.dequeueReusableCell(withIdentifier: "NumberOfBidsForBorrowerTableViewCell1ID") as? NumberOfBidsForBorrowerTableViewCell1
let bidCreatedByBankerData = bidCreatedByBankerArray[indexPath.row]
cell?.projectDescriptionLabel.text = bidCreatedByBankerData.projectDescription
return cell!
}else {
let cell = tableView.dequeueReusableCell(withIdentifier: "NumberOfBidsForBorrowerTableViewCell2ID", for: indexPath) as! NumberOfBidsForBorrowerTableViewCell2
cell.selectionStyle = .default
let bidCreatedByBankerData = tableData[indexPath.row]
cell.cityNameLabel.text = bidCreatedByBankerData.cityName
return cell
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView2.reloadData()
if (tableView == self.tableView1) {
tableView2.isHidden = false
let bidCreatedByBankerData = bidCreatedByBankerArray[indexPath.row]
tableData.removeAll()
tableData.append(bidCreatedByBankerData)
tableView2.reloadData()
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.