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
到