Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift Nib视图不同于模拟器_Swift_Xcode_Ios Simulator_Nib - Fatal编程技术网

Swift Nib视图不同于模拟器

Swift Nib视图不同于模拟器,swift,xcode,ios-simulator,nib,Swift,Xcode,Ios Simulator,Nib,我的笔尖 我的模拟器。我不明白为什么约束不起作用 我认为代码没有影响,但请参见下文: func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if let headeView = Bundle.main.loadNibNamed("HeaderViewCell", owner: self, options: nil)?.first as? Header

我的笔尖

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

我认为代码没有影响,但请参见下文:

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()
}

也许您需要在加载的视图上调用
layoutifneed()

最好的方法是
willDisplayHeaderView:forSection()


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

请确保您正确地给出了imageView的约束。可能是顶部空间领先,高度和宽度也可以。并将imageView的“剪裁到边界”属性设置为true

当我开始制作自定义标题时,我看到了视频教程(),其中标题基于UITableViewCell类。你们可以看到上面的结果

我决定尝试通常的观点,我得到了正确的结果如下。谢谢大家的回答

我想,您为观众提供了哪些有用的答案还不够,您能详细说明一下吗?是否有任何代码可能会影响视图的外观?我在编码方面是新手(不到1年),您的意思是我需要以编程方式设置约束?