Unable to populate data into table view
Unable to populate data into table view
This is Swift 4.
I was not able to populate the data (in the information array) into the table view.
I am expecting the strings "Name", "Date of Birth", "Gender", "Phone", "Email" to show up in the table view but nothing is showing up.
I have entered "ProfileInfo" as my tableViewCell identifier.
Thanks.
let information = ["Name", "Date of Birth", "Gender", "Phone", "Email"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return information.count
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileInfo", for: indexPath) as! OTProfileTableViewCell
cell.label.text = information[indexPath.row]
return cell
1 Answer
1
There are some things the OP didn't include. I assume you are using a UIViewController
subclass with a UITableView
as a subview (since there is another view above the table and this is not as straightforward with a UITableViewController
).
UIViewController
UITableView
UITableViewController
Please try the following if they are not already being done:
tableView.dataSource
viewDidLoad
Is tableView(_:cellForRowAt:)
being called and is the cell you are grabbing the correct type? Use a breakpoint in this method to inspect. If the breakpoint isn't hit you are likely not setting the data source of the table properly.
tableView(_:cellForRowAt:)
Set a breakpoint in tableView(_:numberOfRowsInSection:)
as well. This method should always be executed (as long as you have at least 1section).
tableView(_:numberOfRowsInSection:)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.