简体   繁体   中英

update vertical stack view contents

I'am observing data in firebase, when this data changed, the collectionview reloads it's data, where I remove a label from the vertical stackview, I want to add this label again to the vertical stackview during runtime on some conditions, the vertical stackview is a part of a collectionview cell.

override func layoutSubviews() {
 if(serviceUserCompany.text == ""){
           detailsStackView.removeArrangedSubview(serviceUserCompany)
           serviceUserCompany.isHidden = true
       }

       if(serviceUserCompany.text != "" && !detailsStackView.arrangedSubviews.contains(serviceUserCompany)){
           detailsStackView.insertArrangedSubview(serviceUserCompany, at: 2)
       }
}

Hide it instead of removing it. It'll be reduced to 0 height, and the other views will move up to take its place.

Also don't update your views in layoutSubviews . It'll cause all sorts of weird issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM