【问题标题】:Cannot convert value of type '(_) -> Void?' to expected argument type '(() -> Void)?'无法转换类型“(_)-> Void?”的值到预期的参数类型'(() - > Void)?
【发布时间】:2018-04-09 09:57:04
【问题描述】:

无法转换 '(_) -> Void?' 类型的值到预期的参数类型'(() -> Void)?'

[![在此处输入图片描述][1]][1]

[1]:https://i.stack.imgur.com/M1MYV.png`func deselectSelectedCells() { 如果让开始 = startDateIndexPath { var section = start.section var item = start.item + 1

        if let cell = collectionView?.cellForItem(at: start) as? AirbnbDatePickerCell {
            cell.type.remove([.InBetweenDate, .SelectedStartDate, .SelectedEndDate, .Selected])
            cell.configureCell()
            collectionView?.deselectItem(at: start, animated: false)
        }

        if let end = endDateIndexPath {
            var indexPathArr = [IndexPath]()
            while section < months.count, section <= end.section {
                let curIndexPath = IndexPath(item: item, section: section)
                if let cell = collectionView?.cellForItem(at: curIndexPath) as? AirbnbDatePickerCell {
                    cell.type.remove([.InBetweenDate, .SelectedStartDate, .SelectedEndDate, .Selected])
                    cell.configureCell()
                    collectionView?.deselectItem(at: curIndexPath, animated: false)
                }

                if section == end.section && item >= end.item {
                    // stop iterating beyond end date
                    break
                } else if item >= (collectionView!.numberOfItems(inSection: section) - 1) {
                    // more than num of days in the month
                    section += 1
                    item = 0
                } else {
                    item += 1
                }
            }

            collectionView?.performBatchUpdates({
                (s) in
                self.collectionView?.reloadItems(at: indexPathArr)
            }, completion: nil)
        }
    }
}`

【问题讨论】:

  • 删除(s) in?
  • 在可能的情况下粘贴代码而不是使用屏幕截图,这样可以让他人更轻松地尝试测试您的示例,谢谢!

标签: ios swift uicollectionview


【解决方案1】:

错误告诉您解决方案。 performBatchUpdates 接受不带参数的回调,但你在那里定义了一个参数。

删除performBatchUpdates(第40行)下声明回调参数的(s) in行。

【讨论】:

  • 当我隐藏该行时我遇到了另一个问题,日历之间不显示月份
  • 我已经粘贴了代码让我有解决方案吗?
猜你喜欢
  • 2017-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
相关资源
最近更新 更多