【问题标题】:Crash on UITableView willDisplayCellUITableView willDisplayCell 崩溃
【发布时间】:2018-07-15 23:52:36
【问题描述】:

我的应用程序的特定行出现间歇性崩溃。我无法重现问题。在我使用两台不同的 iPad 和所有模拟器进行的所有测试中,我无法让它崩溃,但在上个月我已经有 36 次用户崩溃。
以下是 CrashLytics 的相关代码和崩溃报告。
始终显示为崩溃的行是;

cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Purchase Full Version Now (%@)",nil), self.sellPrice];

希望有人能提供帮助,我很感激任何建议。

(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UILabel *titleCellLabel = [[UILabel alloc] init];

    if (indexPath.section == 0){
        switch (indexPath.row) {
            case 0:
                cell.textLabel.text = NSLocalizedString(@"Default Type",nil);
                break;
            case 1:
                cell.textLabel.text = NSLocalizedString(@"Default Attendee",nil);
                break;
            case 2:
                cell.textLabel.text = NSLocalizedString(@"PDF Set-up",nil);
                break;
            case 3:
                titleCellLabel.text = NSLocalizedString(@"Topic and Item Numbering",nil);
                titleCellLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
                titleCellLabel.textColor = [UIColor blackColor];
                [titleCellLabel sizeToFit];
                titleCellLabel.frame = CGRectMake(20, 12, titleCellLabel.frame.size.width, titleCellLabel.frame.size.height);
                [[cell contentView] addSubview:titleCellLabel];
                break;
            default:
            break;
        }
    }

    if (indexPath.section == 1){
        switch (indexPath.row) {
            case 0:
                cell.textLabel.text = NSLocalizedString(@"Version",nil);
                break;
            case 1:
                cell.textLabel.text = NSLocalizedString(@"Feedback",nil);
                break;
            case 2:
                cell.textLabel.text = NSLocalizedString(@"Help",nil);
                break;

            default:
                break;
        }
    }

    if (indexPath.section == 2){
        switch (indexPath.row) {
            case 0:
               cell.textLabel.text = NSLocalizedString(@"Backup Data to Email",nil);
               break;
            case 1:
                cell.textLabel.text = NSLocalizedString(@"Restore Previous Full Version Purchase",nil);
                break;
            case 2:
                cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Purchase Full Version Now (%@)",nil), self.sellPrice];
                break;

            default:
                break;
        }
    }
}

这是崩溃报告;

# Crashlytics - plaintext stacktrace downloaded by Paul at Tue, 06 Feb 2018 01:22:20 GMT
# Platform: ios
# OS Version: 10.3.3 (14G60)
# Device: iPad 4
# RAM Free: 7.1%
# Disk Free: 13.2%

#0. Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x1aeb1f4c fixupMethodList(method_list_t*, bool, bool) + 103
1  libobjc.A.dylib                0x1aea4d01 NXMapInsert + 62
2  libobjc.A.dylib                0x1aeb19e9 prepareMethodLists(objc_class*, method_list_t**, int, bool, bool) + 88
3  libobjc.A.dylib                0x1aeab2d3 realizeClass(objc_class*) + 918
4  libobjc.A.dylib                0x1aeaebc7 lookUpImpOrForward + 94
5  libobjc.A.dylib                0x1aeaeb65 _class_lookupMethodAndLoadCache3 + 26
6  libobjc.A.dylib                0x1aeb51af _objc_msgSend_uncached + 14
7  Simple Meeting Minutes         0x96697 -[MMSettingsTableVC tableView:willDisplayCell:forRowAtIndexPath:] (MMSettingsTableVC.m:195)
8  UIKit                          0x21179ca9 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 814
9  UIKit                          0x21179de5 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 66
10 UIKit                          0x21167d79 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2190
11 UIKit                          0x2117e8db -[UITableView _performWithCachedTraitCollection:] + 92
12 UIKit                          0x20f2af0f -[UITableView layoutSubviews] + 178
13 UIKit                          0x20e49483 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1224
14 QuartzCore                     0x1eaa1cb7 -[CALayer layoutSublayers] + 126
15 QuartzCore                     0x1ea95d77 CA::Layer::layout_if_needed(CA::Transaction*) + 354
16 QuartzCore                     0x1ea95c05 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
17 QuartzCore                     0x1ea24839 CA::Context::commit_transaction(CA::Transaction*) + 320
18 QuartzCore                     0x1ea42fdb CA::Transaction::commit() + 578
19 UIKit                          0x20e3f93b _afterCACommitHandler + 238
20 CoreFoundation                 0x1bbdb803 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
21 CoreFoundation                 0x1bbd9a55 __CFRunLoopDoObservers + 282
22 CoreFoundation                 0x1bbda017 __CFRunLoopRun + 1358
23 CoreFoundation                 0x1bb2d1af CFRunLoopRunSpecific + 470
24 CoreFoundation                 0x1bb2cfd1 CFRunLoopRunInMode + 104
25 GraphicsServices               0x1d2d7b41 GSEventRunModal + 80
26 UIKit                          0x20eafa53 UIApplicationMain + 150
27 App Name                       0x63123 main (main.m:16)
28 libdyld.dylib                  0x1b31a4eb start + 2

#0. Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x1aeb1f4c fixupMethodList(method_list_t*, bool, bool) + 103
1  libobjc.A.dylib                0x1aea4d01 NXMapInsert + 62
2  libobjc.A.dylib                0x1aeb19e9 prepareMethodLists(objc_class*, method_list_t**, int, bool, bool) + 88
3  libobjc.A.dylib                0x1aeab2d3 realizeClass(objc_class*) + 918
4  libobjc.A.dylib                0x1aeaebc7 lookUpImpOrForward + 94
5  libobjc.A.dylib                0x1aeaeb65 _class_lookupMethodAndLoadCache3 + 26
6  libobjc.A.dylib                0x1aeb51af _objc_msgSend_uncached + 14
7  App Name                       0x96697 -[MMSettingsTableVC tableView:willDisplayCell:forRowAtIndexPath:] (MMSettingsTableVC.m:195)
8  UIKit                          0x21179ca9 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 814
9  UIKit                          0x21179de5 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 66
10 UIKit                          0x21167d79 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2190
11 UIKit                          0x2117e8db -[UITableView _performWithCachedTraitCollection:] + 92
12 UIKit                          0x20f2af0f -[UITableView layoutSubviews] + 178
13 UIKit                          0x20e49483 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1224
14 QuartzCore                     0x1eaa1cb7 -[CALayer layoutSublayers] + 126
15 QuartzCore                     0x1ea95d77 CA::Layer::layout_if_needed(CA::Transaction*) + 354
16 QuartzCore                     0x1ea95c05 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
17 QuartzCore                     0x1ea24839 CA::Context::commit_transaction(CA::Transaction*) + 320
18 QuartzCore                     0x1ea42fdb CA::Transaction::commit() + 578
19 UIKit                          0x20e3f93b _afterCACommitHandler + 238
20 CoreFoundation                 0x1bbdb803 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
21 CoreFoundation                 0x1bbd9a55 __CFRunLoopDoObservers + 282
22 CoreFoundation                 0x1bbda017 __CFRunLoopRun + 1358
23 CoreFoundation                 0x1bb2d1af CFRunLoopRunSpecific + 470
24 CoreFoundation                 0x1bb2cfd1 CFRunLoopRunInMode + 104
25 GraphicsServices               0x1d2d7b41 GSEventRunModal + 80
26 UIKit                          0x20eafa53 UIApplicationMain + 150
27 App Name                       0x63123 main (main.m:16)
28 libdyld.dylib                  0x1b31a4eb start + 2

#1. Thread
0  libsystem_kernel.dylib         0x1b3ee73c __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1b4a2745 _pthread_wqthread + 728
2  libsystem_pthread.dylib        0x1b4a245c start_wqthread + 8

#2. com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1b3d8900 mach_msg_trap + 20
1  libsystem_kernel.dylib         0x1b3d86e1 mach_msg + 44
2  CoreFoundation                 0x1bbdbbe3 __CFRunLoopServiceMachPort + 144
3  CoreFoundation                 0x1bbda065 __CFRunLoopRun + 1436
4  CoreFoundation                 0x1bb2d1af CFRunLoopRunSpecific + 470
5  CoreFoundation                 0x1bb2cfd1 CFRunLoopRunInMode + 104
6  Foundation                     0x1c481af5 <redacted> + 258
7  Foundation                     0x1c49e76d <redacted> + 86
8  UIKit                          0x217b0ad9 -[UIEventFetcher threadMain] + 128
9  Foundation                     0x1c5658eb <redacted> + 1122
10 libsystem_pthread.dylib        0x1b4a493b _pthread_body + 216
11 libsystem_pthread.dylib        0x1b4a485d _pthread_start + 234
12 libsystem_pthread.dylib        0x1b4a2468 thread_start + 8

#3. com.twitter.crashlytics.ios.MachExceptionServer
0  App Name                       0xbb343 CLSProcessRecordAllThreads + 1057603
1  App Name                       0xbb343 CLSProcessRecordAllThreads + 1057603
2  App Name                       0xbb23b CLSProcessRecordAllThreads + 1057339
3  App Name                       0xaf18d CLSHandler + 1008013
4  App Name                       0xaaed7 CLSMachExceptionServer + 990935
5  libsystem_pthread.dylib        0x1b4a493b _pthread_body + 216
6  libsystem_pthread.dylib        0x1b4a485d _pthread_start + 234
7  libsystem_pthread.dylib        0x1b4a2468 thread_start + 8

#4. com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1b3d8900 mach_msg_trap + 20
1  libsystem_kernel.dylib         0x1b3d86e1 mach_msg + 44
2  CoreFoundation                 0x1bbdbbe3 __CFRunLoopServiceMachPort + 144
3  CoreFoundation                 0x1bbda065 __CFRunLoopRun + 1436
4  CoreFoundation                 0x1bb2d1af CFRunLoopRunSpecific + 470
5  CoreFoundation                 0x1bb2cfd1 CFRunLoopRunInMode + 104
6  CFNetwork                      0x1c20a393 +[NSURLConnection(Loader) _resourceLoadLoop:] + 402
7  Foundation                     0x1c5658eb <redacted> + 1122
8  libsystem_pthread.dylib        0x1b4a493b _pthread_body + 216
9  libsystem_pthread.dylib        0x1b4a485d _pthread_start + 234
10 libsystem_pthread.dylib        0x1b4a2468 thread_start + 8

#5. Thread
0  libsystem_kernel.dylib         0x1b3ed808 __psynch_cvwait + 24
1  libsystem_pthread.dylib        0x1b4a3c43 _pthread_cond_wait + 560
2  libsystem_pthread.dylib        0x1b4a4fc5 pthread_cond_wait + 38
3  libc++.1.dylib                 0x1ae3fc57 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 118
4  JavaScriptCore                 0x1fa94261 <redacted> + 88
5  JavaScriptCore                 0x1fa941e5 <redacted> + 154
6  JavaScriptCore                 0x1fa940ed <redacted> + 18
7  JavaScriptCore                 0x1fa9432f <redacted> + 66
8  libsystem_pthread.dylib        0x1b4a493b _pthread_body + 216
9  libsystem_pthread.dylib        0x1b4a485d _pthread_start + 234
10 libsystem_pthread.dylib        0x1b4a2468 thread_start + 8

#6. WebThread
0  libsystem_kernel.dylib         0x1b3d8900 mach_msg_trap + 20
1  libsystem_kernel.dylib         0x1b3d86e1 mach_msg + 44
2  CoreFoundation                 0x1bbdbbe3 __CFRunLoopServiceMachPort + 144
3  CoreFoundation                 0x1bbda065 __CFRunLoopRun + 1436
4  CoreFoundation                 0x1bb2d1af CFRunLoopRunSpecific + 470
5  CoreFoundation                 0x1bb2cfd1 CFRunLoopRunInMode + 104
6  WebCore                        0x1fd4bce3 <redacted> + 426
7  libsystem_pthread.dylib        0x1b4a493b _pthread_body + 216
8  libsystem_pthread.dylib        0x1b4a485d _pthread_start + 234
9  libsystem_pthread.dylib        0x1b4a2468 thread_start + 8

#7. Thread
0  libsystem_kernel.dylib         0x1b3ee73c __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1b4a28eb _pthread_wqthread + 1150
2  libsystem_pthread.dylib        0x1b4a245c start_wqthread + 8

#8. Thread
0  libsystem_kernel.dylib         0x1b3ee73c __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1b4a28eb _pthread_wqthread + 1150
2  libsystem_pthread.dylib        0x1b4a245c start_wqthread + 8

【问题讨论】:

  • 首先,你为什么要修改willDisplayCell中的UI???为什么不能在 cellForRowAtIndexPath 中配置单元格,这就是它的用途。其次,每次调用 willDisplayCell 时,您都会在单元格的 contentView 中添加一个新标签.. 单元格会被回收,所以如果我滚动你的表格100 次,第 0 部分中的第 4 个单元格将有 100 个标签。最后,self.sellPrice是什么类型???你确定是字符串吗?
  • 嗨,布兰登,感谢您的评论。我正在使用 willDisplayCell 因为我需要向其中一个单元格添加子视图标签。因为它是一个静态表,所以我认为这是最好的,而不是 cellForRowAtIndexPath。 self.sellPrice 绝对是一个字符串。关于在表格滚动时添加新标签的要点。
    我所做的是不使用 willDisplayCell 而是在 Storybook 中为每个单元格创建 IBOutlet 并从 viewDidLoad 设置单元格测试标签。这似乎工作正常,并有望更加稳定。
  • 你是不是忘记了细胞是重复使用的?您最终可能会在每个单元格中添加此子视图!
  • @Brandon cellForRowAtIndexPath 如果您想要真正平滑的滚动,则意味着尽快完成。 willDisplayCell 是填充单元格的最佳位置,但这不是添加视图。看看这个:medium.com/ios-os-x-development/…看看第一个亮点。
  • @Stoyan; jobs.zalando.com/tech/blog/…我从未见过代码在willDisplay而不是cellForRow中配置单元格

标签: ios objective-c uitableview ipad


【解决方案1】:

正如 Brandon 所指出的,使用 willDisplayCell 并在每次滚动时添加一个新的单元格内容标签可能是问题所在。我使用 willDisplayCell 因为我需要向其中一个单元格添加子视图标签。
因此,我没有使用 willDisplayCell,而是在 Storybook 中为每个单元格创建 IBOutlet,设置单元格文本标签并从内部加载单元格子视图viewDidLoad。这似乎工作正常,应该更稳定。
感谢布兰登的帮助,只是需要有人指出显而易见的事情。

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    • 2011-08-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    相关资源
    最近更新 更多