gpt4 book ai didi

ios - UITableViewCell 崩溃

转载 作者:行者123 更新时间:2023-12-01 18:36:56 25 4
gpt4 key购买 nike

我的代码中有一个奇怪的崩溃,它在准备 UITableViewCell 时崩溃了。 .崩溃报告不令人满意的原因是什么。

Crashed: com.apple.main-thread
0 Quickride 0x104c2434c specialized NotificationViewController.tableView(_:cellForRowAt:) (NotificationViewController.swift:222)
1 Quickride 0x104c1fdcc @objc NotificationViewController.tableView(_:cellForRowAt:) (NotificationViewController.swift)
2 UIKitCore 0x1c7abc540 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 684
3 UIKitCore 0x1c7abca88 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
4 UIKitCore 0x1c7a88160 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2256
5 UIKitCore 0x1c7aa604c -[UITableView layoutSubviews] + 140
6 UIKitCore 0x1c7d3aea4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1380
7 QuartzCore 0x19ecbac70 -[CALayer layoutSublayers] + 184
8 QuartzCore 0x19ecbfc00 CA::Layer::layout_if_needed(CA::Transaction*) + 324
9 UIKitCore 0x1c7d26390 -[UIView(Hierarchy) layoutBelowIfNeeded] + 548
10 UIKitCore 0x1c723a6d0 -[UINavigationController _layoutViewController:] + 1296
11 UIKitCore 0x1c7234dc4 -[UINavigationController _layoutTopViewController] + 236
12 UIKitCore 0x1c7232f94 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 780
13 UIKitCore 0x1c7cf5fd8 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 420
14 UIKitCore 0x1c7cf6294 -[UINavigationTransitionView _cleanupTransition] + 588
15 UIKitCore 0x1c7d04154 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 312
16 UIKitCore 0x1c7cffb90 +[UIViewAnimationState popAnimationState] + 336
17 UIKitCore 0x1c7cf5d1c -[UINavigationTransitionView transition:fromView:toView:] + 1864
18 UIKitCore 0x1c723b4e0 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2656
19 UIKitCore 0x1c723babc -[UINavigationController _startDeferredTransitionIfNeeded:] + 1184
20 UIKitCore 0x1c723cdbc -[UINavigationController __viewWillLayoutSubviews] + 164
21 UIKitCore 0x1c721efac -[UILayoutContainerView layoutSubviews] + 224
22 UIKitCore 0x1c7d3aea4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1380
23 QuartzCore 0x19ecbac70 -[CALayer layoutSublayers] + 184
24 QuartzCore 0x19ecbfc00 CA::Layer::layout_if_needed(CA::Transaction*) + 324
25 QuartzCore 0x19ec1e718 CA::Context::commit_transaction(CA::Transaction*) + 340
26 QuartzCore 0x19ec4d04c CA::Transaction::commit() + 608
27 QuartzCore 0x19ec4deb4 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
28 CoreFoundation 0x19a6577a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
29 CoreFoundation 0x19a65243c __CFRunLoopDoObservers + 412
30 CoreFoundation 0x19a6529dc __CFRunLoopRun + 1264
31 CoreFoundation 0x19a6521cc CFRunLoopRunSpecific + 436
32 GraphicsServices 0x19c8c9584 GSEventRunModal + 100
33 UIKitCore 0x1c7895054 UIApplicationMain + 212
34 Quickride 0x104b9968c main (AppDelegate.swift:29)
35 libdyld.dylib 0x19a112bb4 start + 4

这是发生崩溃的代码:-
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if notifications.count <= indexPath.row{
return tableView.dequeueReusableCell(withIdentifier: "non_action") as!NotificationWithActionTableViewCell
}

let notification = notifications[indexPath.row]
let notificationHandler = NotificationHandlerFactory.getNotificationHandler(clientNotification: notification)

var cell:NotificationWithActionTableViewCell?

if notification.isActionRequired == true && notification.isActionTaken == false{
if (notificationHandler!.getPositiveActionNameWhenApplicable(userNotification: notification) != nil || notificationHandler!.getNegativeActionNameWhenApplicable(userNotification: notification) != nil || notificationHandler!.getNeutralActionNameWhenApplicable(userNotification: notification) != nil){
cell = tableView.dequeueReusableCell(withIdentifier: "action") as? NotificationWithActionTableViewCell
handleUnReadNotification(cell: cell!, notification: notification,notificationHandler : notificationHandler!, indexPath : indexPath as NSIndexPath)
}else{
cell = tableView.dequeueReusableCell(withIdentifier: "non_action") as? NotificationWithActionTableViewCell

cell!.iboDetail.textColor = UIColor(netHex: 0x3c3c3c)
cell!.notifictionRowBackGround.backgroundColor = UIColor(netHex: 0xffffcc)
}

}else{
cell = tableView.dequeueReusableCell(withIdentifier: "non_action") as? NotificationWithActionTableViewCell
handleReadNotification(cell: cell!, notification: notification)
}
cell!.setNotificationIconAndTitle(notificationHandler: notificationHandler, notification: notification)
cell!.iboTimeStamp.text = DateUtils.getTimeStringFromTimeInMillis(timeStamp: Double(notification.time!)*1000, timeFormat: DateUtils.DATE_FORMAT_dd_MMM_hh_mm_aaa)
if notification.sendFrom != 0{
cell?.iboNotificationIcon?.isUserInteractionEnabled = true
cell?.iboNotificationIcon?.tag = indexPath.row
cell?.iboNotificationIcon?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(NotificationViewController.notificaitonIconTapped(_:))))
}
else{
cell?.iboNotificationIcon?.isUserInteractionEnabled = false
}

return cell!

}

崩溃发生在上述代码的以下行:-
 cell!.iboDetail.textColor = UIColor(netHex: 0x3c3c3c)

任何解决方案的家伙。尝试了很多但无法解决问题。提前致谢

最佳答案

崩溃的原因是在上一行

cell = tableView.dequeueReusableCell(withIdentifier: "non_action") as? NotificationWithActionTableViewCell

...你最终得到 cell正在 nil .当表格 View 无法出列时,您必须自己创建单元格。

当然,如果您调用 dequeueReusableCell(withIdentifier:forIndexPath:)相反,像其他人一样,你永远不会得到 nil并且不会出现问题。

关于ios - UITableViewCell 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53663430/

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