Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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
Ios 为什么无论输入什么约束,子视图的子视图都不会出现?_Ios_Swift_Xcode - Fatal编程技术网

Ios 为什么无论输入什么约束,子视图的子视图都不会出现?

Ios 为什么无论输入什么约束,子视图的子视图都不会出现?,ios,swift,xcode,Ios,Swift,Xcode,我有一个视图控制器,在它的视图中添加了一个UIView。在这里面,我尝试向它添加子视图,例如uipickerview和segment控件 问题是,无论我添加了什么约束,如果我将headerView.translatesAutoresizingMaskIntoConstraints=false放在包含它们的视图中,它们都不会出现。以下是我对所有视图的约束 view.addSubview(tableView) //设置HeaderView var headerView=UIView() self.v

我有一个视图控制器,在它的视图中添加了一个
UIView
。在这里面,我尝试向它添加子视图,例如uipickerview和segment控件

问题是,无论我添加了什么约束,如果我将
headerView.translatesAutoresizingMaskIntoConstraints=false
放在包含它们的视图中,它们都不会出现。以下是我对所有视图的约束

view.addSubview(tableView)
//设置HeaderView
var headerView=UIView()
self.view.addSubview(headerView)
headerView.backgroundColor=.systemRed
headerView.translatesAutoresizingMaskIntoConstraints=false
headerView.leadingAnchor.constraint(等式:self.view.leadingAnchor).isActive=true
headerView.trailingAnchor.constraint(equalTo:self.view.trailingAnchor).isActive=true
headerView.heightAnchor.constraint(equalToConstant:50).isActive=true
headerView.topAnchor.constraint(equalTo:self.topLayoutGuide.bottomAnchor).isActive=true
//设置列表选择器
var listPicker=CustomHorizontalPickerView()
headerView.addSubview(列表选择器)
listPicker.topAnchor.constraint(equalTo:headerView.topAnchor).isActive=true
listPicker.leadingAnchor.constraint(equalTo:headerView.leadingAnchor,常量:5)。isActive=true
listPicker.trailingAnchor.constraint(equalTo:headerView.trailingAnchor,常量:-5)。isActive=true
listPicker.heightAnchor.constraint(equalToConstant:headerView.frame.height/2)。isActive=true
setTableViewDelegates()
tableView.rowHeight=50
tableView.translatesAutoresizingMaskIntoConstraints=false
tableView.leadingAnchor.constraint(等式:self.view.leadingAnchor).isActive=true
tableView.trailingAnchor.constraint(equalTo:self.view.trailingAnchor).isActive=true
tableView.bottomAnchor.constraint(equalTo:self.view.bottomAnchor).isActive=true
self.tableView.topAnchor.constraint(equalTo:headerView.bottomAnchor).isActive=true
tableView.register(UINib(nibName:“CustomCellNSB2”,bundle:nil),强制重用标识符:“CustomCellNSB2”)
除非我删除
translatesAutoresizing
,然后它出现在错误的位置,否则我的列表选择器不会出现。感谢您的帮助。

添加

 listPicker.translatesAutoresizingMaskIntoConstraints = false
改变

listPicker.heightAnchor.constraint(equalToConstant: headerView.frame.height / 2 ).isActive = true
  

改变

listPicker.heightAnchor.constraint(equalToConstant: headerView.frame.height / 2 ).isActive = true