У меня странная проблема с тем, как FirebaseUI обрабатывает мой UITableView.Похоже, что при начальной загрузке UITableView он не может отрисовать данные из Firebase.Однако при последующих загрузках проблем не возникает.Не уверен, относится ли это к сохранению в автономном режиме или кешируются данные, но по сути я получаю следующую ошибку при начальной загрузке данных в UITableView:
Ошибка:
2019-01-27 15:05:24.078515-0600 BetShark[7094:381856] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3698.93.8/UITableView.m:1776
2019-01-27 15:05:24.094211-0600 BetShark[7094:381856] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to perform an insert and a move to the same index path (<NSIndexPath: 0x8c28b55a1a1eb51c> {length = 2, path = 0 - 78})'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110f241bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x00000001104ca735 objc_exception_throw + 48
2 CoreFoundation 0x0000000110f23f42 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010bbe4877 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 UIKitCore 0x000000011906c88a -[UITableView _endCellAnimationsWithContext:] + 9355
5 UIKitCore 0x0000000119088711 -[UITableView endUpdates] + 75
6 BetShark 0x0000000107c09405 -[FUIFirestoreTableViewDataSource batchedArray:didUpdateWithDiff:] + 3285
7 BetShark 0x0000000107bf9906 __31-[FUIBatchedArray observeQuery]_block_invoke + 1094
8 BetShark 0x000000010796a628 __60-[FIRQuery addSnapshotListenerInternalWithOptions:listener:]_block_invoke + 456
9 BetShark 0x000000010797d495 _ZZZ45-[FSTAsyncQueryListener asyncSnapshotHandler]EUb_ENK3$_0clEv + 85
10 BetShark 0x000000010797d42d _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZZ45-[FSTAsyncQueryListener asyncSnapshotHandler]EUb_E3$_0EEEvDpOT_ + 45
11 BetShark 0x000000010797d179 _ZNSt3__110__function6__funcIZZ45-[FSTAsyncQueryListener asyncSnapshotHandler]EUb_E3$_0NS_9allocatorIS2_EEFvvEEclEv + 41
12 BetShark 0x00000001079aa3d6 _ZNKSt3__18functionIFvvEEclEv + 102
13 BetShark 0x000000010792b9a1 _ZZN8firebase9firestore4util8internal13DispatchAsyncEPU28objcproto17OS_dispatch_queue8NSObjectONSt3__18functionIFvvEEEENK3$_0clEPv + 33
14 BetShark 0x000000010792b978 _ZZN8firebase9firestore4util8internal13DispatchAsyncEPU28objcproto17OS_dispatch_queue8NSObjectONSt3__18functionIFvvEEEEN3$_08__invokeEPv + 24
15 libdispatch.dylib 0x0000000111f56602 _dispatch_client_callout + 8
16 libdispatch.dylib 0x0000000111f6399a _dispatch_main_queue_callback_4CF + 1541
17 CoreFoundation 0x0000000110e893e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x0000000110e83a76 __CFRunLoopRun + 2342
19 CoreFoundation 0x0000000110e82e11 CFRunLoopRunSpecific + 625
20 GraphicsServices 0x00000001134781dd GSEventRunModal + 62
21 UIKitCore 0x0000000118e6681d UIApplicationMain + 140
22 BetShark 0x0000000107731f07 main + 71
23 libdyld.dylib 0x0000000111fcc575 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Код:
import UIKit
import FirebaseUI
class LeaderboardViewController: UIViewController {
private let ROWS_TO_SHOW = 100
@IBOutlet weak var tableView: UITableView!
fileprivate var dataSource: FUIFirestoreTableViewDataSource!
var leaderboardTitle: String!
var period: String!
override func viewDidLoad() {
super.viewDidLoad()
title = leaderboardTitle
self.tableView.register(UINib(nibName: "LeaderTableViewCell", bundle: nil),
forCellReuseIdentifier: "LeaderTableViewCell")
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
self.tableView.delegate = self
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let query = Firestore.firestore()
.collection("userStats")
.whereField("timePeriodString", isEqualTo: period)
.whereField("statType", isEqualTo: StatType.AMOUNT_NETTED.rawValue)
.order(by:"valueAsDouble", descending: true)
.limit(to: ROWS_TO_SHOW)
self.dataSource = tableView.bind(toFirestoreQuery: query, populateCell: { (tableView, indexPath, snapshot) -> UITableViewCell in
let cell = tableView.dequeueReusableCell(withIdentifier: "LeaderTableViewCell", for: indexPath) as! LeaderTableViewCell
let stat = UserStat(dict: snapshot.data() ?? [:])
cell.setStat(position: indexPath.row, userStat: stat)
return cell
})
self.tableView.reloadData()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.dataSource.unbind()
self.dataSource.tableView = nil
self.tableView.reloadData()
}
}
extension LeaderboardViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let userId = (tableView.cellForRow(at: tableView.indexPathForSelectedRow!) as! LeaderTableViewCell).userStat?.userId ?? ""
ProfileViewController.openPorfile(vc: self, userId: userId)
}
}
extension LeaderboardViewController {
public static func openLeaderboard(sender: UIViewController, leaderboardTitle: String, period: String) {
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "LeaderboardViewController") as! LeaderboardViewController
vc.leaderboardTitle = leaderboardTitle
vc.period = period
sender.navigationController?.pushViewController(vc, animated: true)
}
}