【问题标题】:Nib view differs from Simulator笔尖视图不同于模拟器
【发布时间】:2017-06-05 08:02:58
【问题描述】:

我的笔尖

我的模拟器。我不明白为什么约束不起作用

我认为代码没有影响,但是请看下面:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    if let headeView = Bundle.main.loadNibNamed("HeaderViewCell", owner: self, options: nil)?.first as? HeaderViewCell {

        //headeView.categoryLabel.text = "FFF"
        return headeView
    }




    return UIView()
}

【问题讨论】:

  • 我假设您为观众提供什么来提供有用的答案还不够,您能详细说明一下吗?是否有任何代码可能会影响视图的外观?

标签: swift xcode ios-simulator nib


【解决方案1】:

也许你需要在加载的视图上调用layoutIfNeeded()

最好的地方是willDisplayHeaderView:forSection()

另外,请检查您的约束设置。

【讨论】:

  • 我是编码新手(不到 1 年),您的意思是我需要以编程方式设置约束吗?
【解决方案2】:

请确保您正确地给出了 imageView 的约束。可能是顶部空间领先,高度和宽度可能会。并使imageView的clip to bounds属性为true。

【讨论】:

    【解决方案3】:

    当我开始制作自定义标题时,我看到了视频教程 (https://youtu.be/gEoiiZZE6cw),其中标题基于 UITableViewCell 类。你会看到上面的结果。

    我解决了尝试通常的视图,我得到了正确的结果,如下所示。谢谢大家的回答

    【讨论】:

      猜你喜欢
      • 2012-03-21
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 2019-06-09
      相关资源
      最近更新 更多