Reputation: 673
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
}
Upvotes: 1
Views: 143
Reputation: 76
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
).
Please try the following if they are not already being done:
tableView.dataSource
. You can set this in viewDidLoad
or in interface builder.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.
Set a breakpoint in tableView(_:numberOfRowsInSection:)
as well. This method should always be executed (as long as you have at least 1section).
Upvotes: 4