Reputation: 25
I've come across a very strange issue suddenly in an app I'm building - the tableViewCells in my tableView are not showing up at all, even though the tableView methods are firing (I've checked using print statements within them). The app does not crash, but everything within the table view cell is just not showing up anymore, even though all data variables have been updated.
Below are the tableView methods I've used:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let count = selectedValidInputs.count
return count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = carbonDetailsTable.dequeueReusableCell(withIdentifier: "CarbonDetailsCell") as! CarbonTableViewCell
cell.itemName.text = selectedValidInputs[indexPath.row]
cell.carbonValue.text = carbonValues[indexPath.row]
cell.tip.text = tips[indexPath.row]
cell.hashtag.text = tags[indexPath.row]
return cell
}
Covering some questions that may be asked
I'm very new to coding altogether, so any help and feedback would be much appreciated!
Note that the page is just empty. Even the 'cellBg' variable below, which is just a view and has a background color, does not show up and neither does the app crash - which is a bit weird.
Edit: Since this is being suggested by everyone, just updating here. On printing the results, I get all values: When the input value is "apple" for example, all the values are shown:
count: 1
selectedValidInputs: ["apple (1 kg)"]
carbonValues: ["550 g CO2, same as 22 plastic bags"]
tips: ["Avoid wastage that adds unnecessary methane to the air with decomposition!"]
tags: ["#very-low-carbon-impact"]
Upvotes: 0
Views: 99
Reputation: 341
1) Try to implement also
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
2) Try to implement also
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 40.0
}
And comment the estimatedRowHeight
and rowHeight
setters, to confirm if the cell's autolayout is not broken and table view is unable to determine row height.
(estimatedRowHeight
is basically used just for tableView indicator bar and estimating the content size of tableView)
Upvotes: 0
Reputation: 212
Print your Arrays which you are passing in tableview in CarbonDetailsViewController, and check data is exact as you passed in previous viewcontroller.
Upvotes: 0
Reputation: 147
Number of sections is equal 0, ‘selectedValidInputs’ array is empty or you have not placed all of the code that is initialising it with values.
Upvotes: 1