gpt4 book ai didi

IOS Swift UITableView - 无法解释的边距 - 如何摆脱?

转载 作者:搜寻专家 更新时间:2023-11-01 06:47:29 25 4
gpt4 key购买 nike

所以我有一个带有自定义单元格的 UITableView...

这是单元格:

enter image description here

这是带有 UITableView 的 xib:

enter image description here

我无法解释蓝色单元格两侧的白色边缘???

我试过:

override func viewDidLoad() {
super.viewDidLoad()

...

table.layoutMargins = UIEdgeInsetsZero
table.separatorInset = UIEdgeInsetsZero
}

我什至尝试了 iOS 8 UITableView separator inset 0 not working 的建议:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell:Cell_Jobs = self.table.dequeueReusableCellWithIdentifier("Cell_Jobs") as Cell_Jobs

cell.area.text = "Hello"


// kill insets for iOS 8
let nf = NSNumberFormatter()
let version = nf.numberFromString(UIDevice.currentDevice().systemVersion)

if(version?.floatValue >= 8){
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsZero
}
// iOS 7 and later
if(cell.respondsToSelector("setSeparatorInset:") ) {
cell.separatorInset = UIEdgeInsetsZero
}

return cell
}

但我仍然无法让左右边距消失......

我做错了什么?

XCode6.1.1。为 iOS 8 构建。

这是带有不需要的边距的麻烦输出:

enter image description here


@Teemu Kurppa 更新:

viewDidLoad() 中,我做了:

self.view.backgroundColor = UIColor.yellowColor()
self.table.backgroundColor = UIColor.cyanColor()

tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) 中,我做了:

cell.contentView.backgroundColor = UIColor.redColor()

更新 2:

所以我成功了

  1. 我删除了父 UIView
  2. 我创建了一个新的 UIView
  3. 我重新添加了 UITableView 和 UIActivityIndi​​catorView

我从一个 Objective-C xib(一年多前写的)复制并粘贴 (Apple+C) 到一个新的 Swift xib - 我怀疑有一些有趣的设置挥之不去导致这些无法解释的边距。

谢谢大家的帮助,

enter image description here

最佳答案

对于单元格,试试这个:

override func tableView(tableView: UITableView, 
willDisplayCell cell: UITableViewCell,
forRowAtIndexPath indexPath: NSIndexPath)
{
cell.separatorInset = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsZero
}

但根据编辑的信息,你似乎在 TableView 的容器 View 中有边距。这要么来自您在 TableView 和 View 之间的约束(一一检查),要么您在 View 中有布局边距,在这种情况下尝试;

 override func viewDidLoad() {
// ...
self.view.layoutMargins = UIEdgeInsetsZero
}

关于IOS Swift UITableView - 无法解释的边距 - 如何摆脱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28781965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com