修改UICollectionView页脚

时间:2015-02-23 16:30:40

标签: ios swift

我有一个应用程序,我在UICollectionView中显示公民。有两级公民,基本和高级。高级会员可以查看比基本会员更多的公民。我在Collection View中有一个自定义页脚,它包含一个ActivityIndi​​cator和一个Label。

class CitizensCollectionFooter: UICollectionReusableView {
    @IBOutlet weak var loadingIndicator: UIActivityIndicatorView!
    @IBOutlet weak var loadMoreCitizensLabel: UILabel!
}

如果用户未达到其会员级别的最大限制,则当用户向下滚动靠近CollectionView的底部时,我会显示loadingIndicator。如果基本用户已达到限制,我想停止加载指示器并显示标签。以下是代码中的代码段:

func scrollViewDidScroll(scrollView: UIScrollView) {

    // Populate more photos when the scrollbar indicator is at 90%
    if scrollView.contentOffset.y + view.frame.size.height > scrollView.contentSize.height * 0.9 ) {

        // Check if basic member has max citizens loaded
        if (memLevel == Constants.AccessLevel.PREMIUM && citizenArray.count >= Constants.Filters.THUMBS_MAX_LOAD_BASIC) {
            footerView?.loadingIndicator.stopAnimating()
            footerView?.loadMoreCitizensLabel.hidden = false
            footerView?.loadMoreCitizensLabel.text = "Load More Profiles…"
        } else if ( (memLevel >= Constants.AccessLevel.PREMIUM && citizenArray.count < Constants.Filters.THUMBS_MAX_LOAD_PREMIUM) ||
            (memLevel < Constants.AccessLevel.PREMIUM && citizenArray.count < Constants.Filters.THUMBS_MAX_LOAD_BASIC) ) {
                // Limit of citizens not reached for premium or basic, load more citizens
                footerView?.loadingIndicator.startAnimating()
                footerView?.loadMoreCitizensLabel.hidden = true
                populateCitizens()
        } else {
            // Max citizens loaded for premium
            footerView?.loadingIndicator.stopAnimating()
            footerView?.loadMoreCitizensLabel.hidden = true
        }
    }
}

问题是当我点击这部分代码时,页脚视图不会更新。如果我在

中从头开始有loadingIndicator startAnimating
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView

它将继续显示,然后当基本公民达到最大公民数量时,标签将不会出现,指标仍然显示。有没有人知道如何更新集合视图的页脚而不必再次创建整个集合视图?

0 个答案:

没有答案