尽管调用了reloaddata(),但UICollectionView数据似乎无法重新加载

时间:2018-09-15 17:45:52

标签: ios uicollectionview

我有一个包含七个部分的UICollectionView。添加新数据并尝试重新加载集合视图后,该视图似乎没有更新。

我已经创建了一个指向该函数的通知,该通知将在创建新任务后进行验证。

@objc func loadList(notification: NSNotification){
    collectionView?.reloadData()
}

我有一个用于添加任务的单独视图,并且这些任务已正确添加到userTask数组中,如下所示。

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    for dayIndex in 0...6 {
        let currentDate = Date()

        let day = DateComponents(calendar: nil, timeZone: nil, era: nil, year: nil, month: nil, day: dayIndex, hour: nil, minute: nil, second: nil, nanosecond: nil, weekday: nil, weekdayOrdinal: nil, quarter: nil, weekOfMonth: nil, weekOfYear: nil, yearForWeekOfYear: nil)

        let date = Calendar.current.date(byAdding: day, to: currentDate)

        if userTasks.count != 0 {
            for task in 0...(userTasks.count - 1) {
                if userTasks[task].dueDate == date {
                    weekTasks[dayIndex].append(userTasks[task])
                }
            }
        }

    }

    let taskCell = collectionView.dequeueReusableCell(withReuseIdentifier: "taskCellID", for: indexPath) as! TaskCell

    taskCell.myTask = weekTasks[indexPath.section][indexPath.item]

    return taskCell
}

0 个答案:

没有答案
相关问题