UITableViewCell在运行时看起来与InterfaceBuilder(在iPad上)不同

时间:2015-08-25 17:44:53

标签: ios swift uitableview ipad tableviewcell

我正在使用swift的通用应用程序。基础是SplitViewController。 tableview嵌入在SplitViewController的详细视图中。我的UITableViewCells的背景颜色看起来与预期不同 - 但仅限于iPad。我尝试了以下设置:

Storyboard中的TableView: TableView in Storyboard

观点的层次结构:

Hierarchy of the views

单元格的设置:

Settings of the cell

内容视图的设置:

Settings of the content view

以下是" cellForRowAtIndexPath"的代码:

 let tableData = ["Test User 1", Test User 2"]

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

         var cell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell!

         cell.textLabel!.text  = tableData[indexPath.row]
         cell.textLabel?.textColor = UIColor.whiteColor()
         cell.textLabel?.font = UIFont(name: "HelveticaNeue-Light", size: 

         return cell
     }

tableview在模拟器中看起来像这样:

simulator of tableview

如上所述 - 如果我选择iPhone设备作为模拟器,它看起来是正确的。这是来自iPhone模拟器的图片: iphone version of tableview

我不知道为什么它在iPad上是白色的而不是InterfaceBuilder中定义的深灰色(就像在iPhone上一样)?什么都没有被选中" .....我总是使用任何/任何尺寸等级。我在这里挣扎了好几天

我很满意每一个提示。

提前致谢。 丹尼尔

1 个答案:

答案 0 :(得分:2)

请注意,即使在Xcode7中,通常在(故事板)中仍然存在错误,

你必须在代码中设置单元格的背景颜色,它在故事板中不起作用

class YourCell:UITableViewCell
    {
    override func awakeFromNib()
        {
        super.awakeFromNib()
        self.backgroundColor = UIColor.clearColor()
        }

    }

您可能还有其他问题,但这是一个问题。