首页 > 解决方案 > 使用代码快速堆栈视图隐藏和显示不起作用

问题描述

我正在按照文档“App development with swift”学习iOS应用程序开发,有一个示例“PersonalityQuiz”,我一步一步地学习。在一个视图控件中,有两个堆栈视图,都先隐藏,然后调用updateSingleStack方法如图所示显示堆栈视图:

func updateSingleStack(using answers: [Answer]) {
        singleStackView.isHidden = false
        singleButton1.setTitle(answers[0].text, for: .normal)
        singleButton2.setTitle(answers[1].text, for: .normal)
        singleButton3.setTitle(answers[2].text, for: .normal)
        singleButton4.setTitle(answers[3].text, for: .normal)
    }

但实际上什么也没有出现。

奇怪的是,如果我在 viewControl 中添加一个按钮,并添加一个 Action 来更改属性 singleStackView.isHidden,这个 stackView 会显示和隐藏。

请让我知道这是为什么?以及如何解决它。

谢谢!

标签: iosswift

解决方案


ok, During adding the singleStackView, and overlay another multipleStackView, the installed checkbox was unchecked, I thought it was the same as isHidden = true in the code. But it is not, after I check the installed checkbox for both StackView, now, the code works.


推荐阅读