繁体   English   中英

Swift CollectionView ReloadData代理很奇怪

[英]Swift CollectionView ReloadData Acting Weird

我有一个“收藏夹视图”和一个顶部的按钮,该按钮经过了几天的列表。 对于每一天,集合视图都应该有所不同,我会跟踪字典中的更改。 但是,每次按下按钮时,我都想重新加载数据,但是它选择的是随机单元格。 重新加载数据后,是否再次运行cellforitematindexpath; 如果不是,它到底在运行什么?

这是我的CellForItem代码:

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("availability", forIndexPath: indexPath) as! AvailabilityCell
        var tempList: [Int]
        tempList = self.availability[self.days[index]]! as! [Int]
        cell.timeInterval.text = timeIntervals[indexPath.row]
        cell.timePeriod.text = timesForIntervals[indexPath.row]
        cell.timeInterval.textColor = DARK_BLUE
        cell.timePeriod.textColor = DARK_BLUE
        cell.backView.layer.cornerRadius = 10
        cell.backView.layer.masksToBounds = true
        cell.backView.layer.borderColor = DARK_BLUE.CGColor
        cell.backView.layer.borderWidth = 1
        cell.selected = false
    if (tempList[indexPath.row] == 1) {

                cell.timeInterval.textColor = UIColor.whiteColor()
                cell.backView.backgroundColor = DARK_BLUE
                cell.timePeriod.textColor = UIColor.whiteColor()

    }
        return cell
    }

这是我的单元格已选择/取消选择:

 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! AvailabilityCell
        cell.timeInterval.textColor = UIColor.whiteColor()
        cell.backView.backgroundColor = DARK_BLUE
        cell.timePeriod.textColor = UIColor.whiteColor()
        var tempList: [Int]
        tempList = self.availability[self.days[index]]! as! [Int]
        tempList[indexPath.row] = 1
        self.availability[self.days[index]] = tempList

    }

    func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! AvailabilityCell
        cell.timeInterval.textColor = DARK_BLUE
        cell.backView.backgroundColor = UIColor.whiteColor()
        cell.timePeriod.textColor = DARK_BLUE
        var tempList: [Int]
        tempList = self.availability[self.days[index]]! as! [Int]
        tempList[indexPath.row] = 0
        self.availability[self.days[index]] = tempList

    }

这是重新加载数据的位置:

@IBAction func decreaseDay(sender: AnyObject) {
        index--
        day.text = days[index]
        dispatch_async(dispatch_get_main_queue()) {
            self.timeCollection.reloadData()
        }
        if (index == 0) {
            back.enabled = false
        }

        forward.enabled = true
    }

这是正在发生的事情的视图:它是如何开始的: 如何开始

重新加载时: 重新加载时会发生什么

我相信您应该更改swift collection视图以重新加载左上角的页面。 重新加载数据以选择下载列表中最优先的项目。 希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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