I have no idea what is wrong with my code. I researched around the Internet could not find a way to fix this.
I have two UITableView in same UIViewController. They both have their own UITableView classes and their identifiers assigned properly from the MainStoryboard (checked multiple times, connections are solid.)
inside viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "PortfolioCell")
barTableView.delegate = self
barTableView.dataSource = self
barTableView.register(UITableViewCell.self, forCellReuseIdentifier: "BarCell")
Related code:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView {
return selCur.count
} else {
return selCur.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.tableView {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "PortfolioCell", for: indexPath) as? PortfolioCell else { return UITableViewCell() }
let noVal = selCur.count[indexPath.row].rank ?? 0
let nameVal = selCur.count[indexPath.row].name ?? "N/A"
cell.configureCell(no: noVal, name: nameVal)
}
}
return cell
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "BarCell", for: indexPath) as? BarCell else { return UITableViewCell() }
let noVal = selectedCurrencies[indexPath.row].rank ?? 0
let nameVal = selectedCurrencies[indexPath.row].name ?? "N/A"
cell.configureCell(no: noVal, name: nameVal)
}
}
return cell
}
}
I am guessing, cellForRowAt method returns regular UITableViewCell instead of the custom "PortfolioCell" or "BarCell". I also tried tableView.tag method as well and got the same result.
Thank you in advance.