美文网首页
“安全的”的swift

“安全的”的swift

作者: 山已几孑 | 来源:发表于2017-04-24 15:24 被阅读0次

为了实现一个九宫格的图片选择器,如下图

Simulator Screen Shot 2017年4月24日 下午3.10.08.png

很简单的实现,使用的是collectionView放置图片,给了cell一个点击事件,用来删除当前的图片,然后后面的图片前移

添加的部分就不说了,与题目无关,看代码

图片.png

看代码,很简单的实现,清晰明了,但是一旦进行删除,crash掉了,
报错如下:
Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UICollectionView.m:5781
2017-04-24 15:17:02.808 MutiPhotoPicker[8549:277952] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. *** The number of items contained in an existing section after the update (7) must be equal to the number of items contained in that section before the update (7)***, plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

终点看加粗部分啊,意思是collection删除前后的数据源必须和item的个数相符合,(我的代码没有写错,数据源是dataSource没错!!

当我注释掉 selectAssets.remove(at: (indexPath?.row)!) 之后一切就和平了,这回删除就没有问题了,最后没办法把这句放倒删除item之后去执行了,取巧了

原因未知,难道是collection View默认 了selectAssets 为数据源了?

如果大神知道问题,还请提点一下

相关文章

  • Swift语法1

    目录 Swift 1.类型安全Swift 是一个类型安全(type safe)的语言。由于 Swift 是类型安全...

  • 20200428整理

    比较 OC 与 Swift 简略Swift 容易阅读,语法和文件结构简易化Swift 更加安全,它是类型安全的语言...

  • 2020 总结

    1、Swift对比Objective-C的优缺点? 优点: swift是**类型安全的语言,注重安全,OC注重灵活...

  • swift 对比 oc优缺点

    Swift对比Objective-C的优缺点 优点: swift是类型安全的语言,注重安全,OC注重灵活 swif...

  • “安全的”的swift

    为了实现一个九宫格的图片选择器,如下图 很简单的实现,使用的是collectionView放置图片,给了cell一...

  • iOS 面试之道 阅读笔记(3)

    Swift 直接跳到Swift语言吧。Swift很快很安全,而且就我的感受来说,写Swift有一种写脚本语言的快感...

  • swift 3.0 变量地址打印

    OC 中我们常常会用到地址打印,但是swift有所不同。swift是种类型安全的语言。有些东西做了安全处理,App...

  • Swift 的内存安全

    内存访问的特点 如果有两个访问动作出现在以下情况中,便会发生冲突 至少有一个动作是写入访问 访问的是同一块内存 访...

  • NSNotification

    Objective-C 代码 Swift 代码 线程安全 NSNotification 是线程安全的,但也不是绝对...

  • Swift3.0 基础语法

    Swift特色 苹果宣称Swift的特点是:快速、现代、安全、互动 Swift中取消了预编译指令包括宏 可以使用现...

网友评论

      本文标题:“安全的”的swift

      本文链接:https://www.haomeiwen.com/subject/fprpzttx.html