显然是在监督简单的事情。需要访问另一个堆栈视图中的嵌套堆栈视图。
如果我想为乘客2的所有嵌套stackView设置间距,我该怎么做?
// Select passenger 2
let tag = 2
// Select wrapper stackView for passenger 2
let stackView = self.view.viewWithTag(tag) as! UIStackView!
let nestedStackViews = stackView. <-- WHAT GOES HERE??
for sv in nestedStackViews{
sv?.spacing = 0 // Set nested stackView spacing to 0 to avoid constraint issues
}
要可视化(需要将firstName_P2,surname_P2和email_P2的间距设置为0)
解决方案:根据Winter的回答
为可能苦苦挣扎的其他人提供更多详细信息,请务必将子视图转换为stackview
// Select passenger 2
let tag = 2
// Select wrapper stackView for passenger 2
let stackView = self.view.viewWithTag(tag) as! UIStackView!
if let nestedStackViews = stackView?.subviews{
for sv in nestedStackViews{
let nsv = sv as! UIStackView
nsv.spacing = 0
}
}