ios - Tableview 的 contentView 小于 tableview frame 和 cell

标签 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

最佳答案

我解决了我的问题

iOS 8 UITableView separator inset 0 not working关于分隔符插入的说明

我刚刚将以下代码添加到我的 viewDidLayoutSubviews

tbStores.cellLayoutMarginsFollowReadableWidth = false;

关于ios - Tableview 的 contentView 小于 tableview frame 和 cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40530353/

相关文章:

ios - 为什么当我调用 setContentOffset 滚动到顶部 tableView 时,有时它会走到一半左右?

ios - 为什么在 iOS7 上触摸 UISearchBar 时,我的 UISearchBar 和 UITableView Cell Header 之间会出现间隙?

ios - Parse.com 查询字符串是否包含在数组中

ios - 升级到 Xcode5 后 AVAudioPlayer 在播放时崩溃

ios - NSDateFormatter 和默认语言环境导致错误

ios - 使用协议(protocol)在 swift 中编写自定义函数

arrays - 在 UITableview swift 中使用两个数组

ios - 在 UITableview 内的自动调整大小的标签上设置非常非常长的文本会破坏 NSLayoutConstraint

ios - 访问给定索引路径处的 UICollectionView 单元格

c - 将 Mac OS X 应用程序移植到 iPhone