gpt4 book ai didi

ios - 无法将类型 'NSIndexPath' 的值转换为预期的参数类型 'NSIndexPath'

转载 作者:搜寻专家 更新时间:2023-10-31 22:48:44 25 4
gpt4 key购买 nike

Cannot convert value of type 'NSIndexPath' to expected argument type 'NSIndexPath'

错误在 self.collectionView?.moveItemAtIndexPath(obj[0] as! NSIndexPath, toIndexPath: obj[1] as! NSIndexPath) 行

if let changes = self.objectChanges{
self.collectionView?.performBatchUpdates({ () -> Void in
for change in changes as NSArray as! [NSDictionary] {
change.enumerateKeysAndObjectsUsingBlock { (keyObject:AnyObject!, obj:AnyObject!, stop) -> Void in
let key = keyObject as! NSNumber
let type = NSFetchedResultsChangeType(rawValue: key.unsignedLongValue)!
switch (type)
{
case .Insert:
self.collectionView?.insertItemsAtIndexPaths(obj as! ([NSIndexPath]))
case .Delete:
self.collectionView?.deleteItemsAtIndexPaths(obj as! ([NSIndexPath]))
case .Update:
self.collectionView?.reloadItemsAtIndexPaths(obj as! ([NSIndexPath]))
case .Move:
self.collectionView?.moveItemAtIndexPath(obj[0] as! NSIndexPath, toIndexPath: obj[1] as! NSIndexPath)
default:
break
}
}
}
}, completion: nil)
}

最佳答案

您正在尝试将下标应用于 obj,它是 AnyObject 而不是 Array。您应该将 obj 转换为 [NSIndexPath]:

if let obj = obj as? [NSIndexPath] {
switch (type) {
case .Insert:
self.collectionView?.insertItemsAtIndexPaths(obj)
case .Delete:
self.collectionView?.deleteItemsAtIndexPaths(obj)
case .Update:
self.collectionView?.reloadItemsAtIndexPaths(obj)
case .Move:
self.collectionView?.moveItemAtIndexPath(obj[0], toIndexPath: obj[1])
default:
break
}
}

关于ios - 无法将类型 'NSIndexPath' 的值转换为预期的参数类型 'NSIndexPath',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32825647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com