ios - Programmatically adding UITableView leaves large space to the left of the cells -


so adding uitableview uiviewcontroller programmatically , getting following result:

enter image description here

i make table in viewdidload 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 how setup 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 tried doing suggested answer similar questions.

func tableview(tableview: uitableview, willdisplaycell cell: uitableviewcell, forrowatindexpath indexpath: nsindexpath) {     cell.separatorinset = uiedgeinsetszero     cell.layoutmargins = uiedgeinsetszero } 

i have tried doing stuff not using reusable cells , setting cell frame nothing works.

any or ideas welcome. thanks!

edit:

setting table.separatorinset = uiedgeinsetszero causing empty cells move left in ss shown above. when removed empty cells have large space well.

i have attempted using constraints programmatically see if made difference. got same result sadly enough. 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) 

so issue ios 9 thing need setcelllayoutmarginsfollowreadablewidth = false in order customize insets , margins. haven't run when using story board + constraints not sure if comes when making programmatically.

here code added make work:

override func viewwillappear(animated: bool) {     if #available(ios 9.0, *) {         table.celllayoutmarginsfollowreadablewidth = false     } else {         // fallback on earlier versions     } }  override func viewdidlayoutsubviews() {     table.separatorinset = uiedgeinsetszero     table.layoutmargins = uiedgeinsetszero }  func tableview(tableview: uitableview, willdisplaycell cell: uitableviewcell, forrowatindexpath indexpath: nsindexpath) {     cell.separatorinset = uiedgeinsetszero     cell.preservessuperviewlayoutmargins = false     cell.layoutmargins = uiedgeinsetszero }