我使用的tableview iOS中9,斯威夫特2 我不明白为什么,当我创建一个简单的单元格的表视图,我得到的内容查看的错误的宽度,即使我设置容器查看为1000. 单元格宽度恰好为1000,但textLabel内部小于1000.分隔符居中且宽度错误。UITableViewCell的错误内容宽度
我怎样才能正确地显示我的电池,并覆盖了整个容器的看法?
所有内容均以编程方式创建。
这里是我的代码:
if tableView == nil {
tableView = UITableView(frame: CGRect(x: 0, y: 44/*88*/, width: self.view.bounds.size.width, height: self.view.bounds.size.height - 44/*88*/), style: UITableViewStyle.Plain)
tableView!.delegate = self
tableView!.backgroundColor = .clearColor()
tableView!.dataSource = self
tableView!.rowHeight = 40.0
tableView!.allowsSelection = false
tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
view.addSubview(tableView!)
tableView!.reloadData()
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var MyIdentifier: String = "MyReuseIdentifier"
var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(MyIdentifier)
if cell == nil {
cell = UITableViewCell(style: .Default, reuseIdentifier: MyIdentifier)
}
cell!.textLabel!.text = "Test"
cell!.backgroundColor = .clearColor()
cell!.textLabel!.textColor = .blackColor()
return cell!
}
你的容器视图主视图控制器'视图'? –
尝试更新“textLabel”的框架值。 – BobGao
这里是层次: - 的viewController(不是主要的,但另一个)有自己的看法 - 的tableView即视图 - 控制视图的子视图。 – yax