- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前不确定如何解决这个问题。基本上我有一个表格 View ,我可以通过滑动来删除数据。以下是受影响行的代码。
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
guard let id = CastService.instance.datsSource[indexPath.row].id else {return}
CastService.instance.deleteCast(id: id, completion: { (success) in
if success {
// Have the below line and that crashes. I believe this is because database has already removed the data
tableView.deleteRows(at: [indexPath], with: .fade)
// Added below line to see if reloading data does anything, however nothing happened, data was still there
// self.tableview.reloadData()
}
})
}
}
数据源声明
fileprivate var dataSource = CastService.instance.datsSource
numberOfRowsInSection 代码
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.dataSource.count
}
我目前正在想办法解决这个问题,以便用户可以删除行
下面的崩溃错误
Interstellar Battalion[62182:2255764] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.33.6/UITableView.m:20112018-01-10 22:13:26.879942+0000 Interstellar Battalion[62182:2255764] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'*** First throw call stack:( 0 CoreFoundation 0x000000010f7ed12b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010e934f41 objc_exception_throw + 48 2 CoreFoundation 0x000000010f7f22f2 +[NSException raise:format:arguments:] + 98 3 Foundation 0x000000010e3d5d69 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 4 UIKit 0x0000000110f4f209 -[UITableView _endCellAnimationsWithContext:] + 19416 5 UIKit 0x0000000110f6b67a -[UITableView _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:] + 1380 6 UIKit 0x0000000110f6b8ba -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 121 7 Interstellar Battalion 0x000000010ddab8f2 _T022Interstellar_Battalion28MovieCastTableViewControllerC05tableF0ySo07UITableF0C_SC0iF16CellEditingStyleO6commit10Foundation9IndexPathV8forRowAttFySbcfU_ + 258 8 Interstellar Battalion 0x000000010ddababc _T022Interstellar_Battalion28MovieCastTableViewControllerC05tableF0ySo07UITableF0C_SC0iF16CellEditingStyleO6commit10Foundation9IndexPathV8forRowAttFySbcfU_TA + 140 9 Interstellar Battalion 0x000000010dda9604 _T022Interstellar_Battalion11CastServiceC06deleteC0ySi2id_ySbc10completiontFy9Alamofire12DataResponseVySSGcfU_ + 612 10 Interstellar Battalion 0x000000010dda9ae2 _T022Interstellar_Battalion11CastServiceC06deleteC0ySi2id_ySbc10completiontFy9Alamofire12DataResponseVySSGcfU_TA + 66 11 Alamofire 0x000000010e135ff5 _T09Alamofire12DataResponseVySSGIxx_ADIxi_TR + 213 12 Alamofire 0x000000010e136092 _T09Alamofire12DataResponseVySSGIxx_ADIxi_TRTA + 66 13 Alamofire 0x000000010e131809 _T09Alamofire11DataRequestC8responseACXDSo13DispatchQueueCSg5queue_x0D10SerializeryAA0B8ResponseVy16SerializedObjectQzGc17completionHandlertAA0biH8ProtocolRzlFyycfU_yycfU_ + 905 14 Alamofire 0x000000010e13a07e _T09Alamofire11DataRequestC8responseACXDSo13DispatchQueueCSg5queue_x0D10SerializeryAA0B8ResponseVy16SerializedObjectQzGc17completionHandlertAA0biH8ProtocolRzlFyycfU_yycfU_TA + 110 15 Alamofire 0x000000010e0e87f9 _T0Ix_IyB_TR + 41 16 libdispatch.dylib 0x0000000114c122f7 _dispatch_call_block_and_release + 12 17 libdispatch.dylib 0x0000000114c1333d _dispatch_client_callout + 8 18 libdispatch.dylib 0x0000000114c1e5f9 _dispatch_main_queue_callback_4CF + 628 19 CoreFoundation 0x000000010f7afe39 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 20 CoreFoundation 0x000000010f774462 __CFRunLoopRun + 2402 21 CoreFoundation 0x000000010f773889 CFRunLoopRunSpecific + 409 22 GraphicsServices 0x00000001183469c6 GSEventRunModal + 62 23 UIKit 0x0000000110e2b5d6 UIApplicationMain + 159 24 Interstellar Battalion 0x000000010dda6c37 main + 55 25 libdyld.dylib 0x0000000114c8fd81 start + 1)libc++abi.dylib: terminating with uncaught exception of type NSException
最佳答案
您收到此崩溃是因为当您在 UITableView
中添加或删除行时,您还需要从数据源中添加或删除相同数量的项目。
例如,您可以将函数更改为:
self.dataSource.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
关于ios - 在tableview中删除一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48196939/
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!