Reputation: 101
I have configured a tableview in my main storyboard which has a button in the prototype cell. However, when I run it, the tableview cells show up without the button. Here is an image of my storyboard:
Can someone explain why it won't show up when I run the program?
Upvotes: 0
Views: 1046
Reputation: 156
Just place a break point on your UITableViewDataSource methods. If they are not calling then just go on your storyboard file and set the tableview delegate and datasource in your view controller.
Upvotes: 0
Reputation: 17
set background colour of button so that we can check button is created or not. or make sure you can add constraints of UIButton
Upvotes: 0
Reputation: 1162
The problem is with the height of the table cell. Button is not showing because the height of the cell is small. You must You have to implement the tableView heightForRowAt indexPath
Method.
Before that Assign Delegate
and DtataSource
Method to the tableView.
override func viewDidLoad(){
super.viewDidLoad()
tableview.delegate = self
tableview.datasource = self
}
If already assign then.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 105
}
Or I think you can also adjust the height from the Size Inspector check the custom height box and provide custom height. And also set proper constraint.
Upvotes: 0
Reputation: 24341
Checklist:
1. Set tableView's
delegate
and dataSource
to the controller
, i.e.
tableView.delegate = self
tableView.dataSource = self
2. Check if the height
of tableViewCell
is not 0
.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 200.0 //Actual height of the cell
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 100.0
}
3. What constraints
have you added to the button
? Try adding centeredHorizontally
and centeredVertically
constraints
to the UIButton
.
Upvotes: 1