So I am adding a UITableView
to a UIViewController
programmatically and I am getting the following result:
I make the table in viewDidLoad
like so:
let size = view.bounds.size
table = UITableView(frame: CGRectMake(0, 65, size.width, size.height-65), style: .Plain)
table.delegate = self
table.dataSource = self
table.separatorInset = UIEdgeInsetsZero
table.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
This is how I setup the cells
:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "cell")
cell.selectionStyle = .None
cell.imageView?.image = blueCheck
cell.textLabel?.text = "TEXT"
cell.separatorInset = UIEdgeInsetsZero
return cell
}
I have also tried doing this which is a suggested answer to similar questions.
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
}
I have also tried doing stuff like not using reusable cells
and setting the cell
frame but nothing works.
Any help or ideas is welcome. Thanks!
EDIT:
Setting table.separatorInset = UIEdgeInsetsZero
is what is causing the empty cells
to move to the left like in the SS shown above. When that is removed the empty cells
have the large space as well.
I have also attempted using constraints programmatically to see if that made any difference. I got the same result sadly enough. This is what I tried:
let bottomConstraint = NSLayoutConstraint(item: table, attribute: NSLayoutAttribute.BottomMargin, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.BottomMargin, multiplier: 1, constant: 0)
let topConstraint = NSLayoutConstraint(item: table, attribute: NSLayoutAttribute.TopMargin, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.TopMargin, multiplier: 1, constant: 65)
let leftConstraint = NSLayoutConstraint(item: table, attribute: NSLayoutAttribute.LeadingMargin, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.LeadingMargin, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: table, attribute: NSLayoutAttribute.TrailingMargin, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.TrailingMargin, multiplier: 1, constant: 0)