Tableview的contentView小于tableview框架和单元格

时间:2016-11-10 14:44:36

标签: ios uitableview

我使用以下代码以编程方式创建Tableview:

 override func viewDidLayoutSubviews() {
    //@begin store selection - settings
    self.tbStores = UITableView(frame: CGRect(x: 15, y: 60, width: UIScreen.main.bounds.size.width - 30, height: 150))
    self.tbStores.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    tbStores.backgroundColor = UIColor.white
    tbStores.delegate = self
    tbStores.dataSource = self
    tbStores.allowsSelection = true;
    tbStores.translatesAutoresizingMaskIntoConstraints = true
 }

并添加了以编程方式创建的ViewAutoComplete

if (viewAutoComplete == nil) {
            self.viewAutoComplete = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
            viewAutoComplete.backgroundColor = UIColor(red: 32 / 255.0, green: 48 / 255.0, blue: 90 / 255.0, alpha: 1)
            viewAutoComplete.alpha = 1
            viewAutoComplete.translatesAutoresizingMaskIntoConstraints = true
            self.viewAutoComplete.tag = 123
    self.view!.addSubview(viewAutoComplete)
            viewAutoComplete.addSubview(tbStores)
}

问题是contentView小于cell和tableview,如下面的截图

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

我在

之后解决了我的问题 有关分隔符插入的

iOS 8 UITableView separator inset 0 not working说明

我刚将以下代码添加到 viewDidLayoutSubviews

tbStores.cellLayoutMarginsFollowReadableWidth = false;