专门的Cell.init(coder :)崩溃

时间:2019-01-25 12:44:26

标签: ios swift uitableview

我在Firebase上遇到了崩溃<compiler-generated> line 0 specialized MessagesCell.init(coder:),仅在iOS 9.2.x或9上才收到此崩溃,我试图对其进行跟踪并了解到底发生了什么,但是在模拟器上却没有发生

这是我为tableView注册单元格的方式:

self.messagesTable.register(MessagesCell.self, forCellReuseIdentifier: "MessagesCell")
self.messagesTable.register(UINib(nibName: "MessagesCell", bundle: nil), forCellReuseIdentifier: "MessagesCell")

这是我的细胞班:

import UIKit

class MessagesCell: UITableViewCell {

    @IBOutlet  var myContentView: UIView!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

这是崩溃日志,我们将不胜感激:

Crashed: com.apple.main-thread
0  libsystem_malloc.dylib         0x183333be8 szone_free + 2944
1  libsystem_malloc.dylib         0x183333738 szone_free + 1744
2  CoreFoundation                 0x1836459a4 CFRelease + 1088
3  CoreUI                         0x18827e40c -[CUIStructuredThemeStore renditionWithKey:usingKeySignature:] + 1600
4  CoreUI                         0x1882a035c -[CUICatalog _storageRefForRendition:representsODRContent:] + 104
5  CoreUI                         0x1882a0124 -[CUICatalog namedLookupWithName:scaleFactor:deviceIdiom:deviceSubtype:sizeClassHorizontal:sizeClassVertical:] + 188
6  UIKit                          0x188cb5994 __98-[_UIAssetManager imageNamed:scale:idiom:subtype:cachingOptions:sizeClassPair:attachCatalogImage:]_block_invoke + 424
7  UIKit                          0x188cb5734 -[_UIAssetManager imageNamed:scale:idiom:subtype:cachingOptions:sizeClassPair:attachCatalogImage:] + 212
8  UIKit                          0x188472320 -[_UIAssetManager imageNamed:scale:idiom:subtype:] + 140
9  UIKit                          0x1889235e0 -[UIImageNibPlaceholder initWithCoder:] + 488
10 UIKit                          0x1946dacfc -[UIImageNibPlaceholderAccessibility initWithCoder:] + 52
11 UIKit                          0x188a4267c UINibDecoderDecodeObjectForValue + 672
12 UIKit                          0x188a423c4 -[UINibDecoder decodeObjectForKey:] + 336
13 UIKit                          0x1888058f4 -[UIImageView initWithCoder:] + 132
14 UIKit                          0x188a4267c UINibDecoderDecodeObjectForValue + 672
15 UIKit                          0x188a427f4 UINibDecoderDecodeObjectForValue + 1048
16 UIKit                          0x188a423c4 -[UINibDecoder decodeObjectForKey:] + 336
17 UIKit                          0x18875c5d0 -[UIView initWithCoder:] + 608
18 UIKit                          0x188a4267c UINibDecoderDecodeObjectForValue + 672
19 UIKit                          0x188a427f4 UINibDecoderDecodeObjectForValue + 1048
20 UIKit                          0x188a423c4 -[UINibDecoder decodeObjectForKey:] + 336
21 UIKit                          0x18875c5d0 -[UIView initWithCoder:] + 608
22 UIKit                          0x188a93678 -[UITableViewCellContentView initWithCoder:] + 48
23 UIKit                          0x188a4267c UINibDecoderDecodeObjectForValue + 672
24 UIKit                          0x188a427f4 UINibDecoderDecodeObjectForValue + 1048
25 UIKit                          0x188a423c4 -[UINibDecoder decodeObjectForKey:] + 336
26 UIKit                          0x18875c5d0 -[UIView initWithCoder:] + 608
27 UIKit                          0x1888f4630 -[UITableViewCell initWithCoder:] + 100
28 APP_NAME                       0x100085464 specialized MessagesCell.init(coder:) (<compiler-generated>)
29 APP_NAME                       0x100084fb0 @objc MessagesCell.init(coder:) (<compiler-generated>)
30 UIKit                          0x1889224b8 -[UIClassSwapper initWithCoder:] + 248
31 UIKit                          0x188a4267c UINibDecoderDecodeObjectForValue + 672
32 UIKit                          0x188a423c4 -[UINibDecoder decodeObjectForKey:] + 336
33 UIKit                          0x188922128 -[UIRuntimeConnection initWithCoder:] + 136
34 UIKit                          0x188a4267c UINibDecoderDecodeObjectForValue + 672
35 UIKit                          0x188a427f4 UINibDecoderDecodeObjectForValue + 1048
36 UIKit                          0x188a423c4 -[UINibDecoder decodeObjectForKey:] + 336
37 UIKit                          0x188921490 -[UINib instantiateWithOwner:options:] + 1220
38 UIKit                          0x1885a3c18 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 584
39 UIKit                          0x1946a5954 -[UITableViewAccessibility dequeueReusableCellWithIdentifier:] + 140
40 UIKit                          0x1885dfbd4 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 88
41 UIKit                          0x1946a5a18 -[UITableViewAccessibility dequeueReusableCellWithIdentifier:forIndexPath:] + 180
42 APP_NAME                       0x1000c07bc MessagesDetail.tableView(_:cellForRowAt:) (MessagesDetail.swift:320)
43 APP_NAME                       0x1000c1c84 @objc MessagesDetail.tableView(_:cellForRowAt:) (<compiler-generated>)
44 UIKit                          0x1887a931c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 692
45 UIKit                          0x1887a9484 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
46 UIKit                          0x1887987e8 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360
47 UIKit                          0x1887adfb0 -[UITableView _performWithCachedTraitCollection:] + 104
48 UIKit                          0x18854308c -[UITableView layoutSubviews] + 176
49 UIKit                          0x188453778 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 656
50 QuartzCore                     0x185e62b2c -[CALayer layoutSublayers] + 148
51 QuartzCore                     0x185e5d738 CA::Layer::layout_if_needed(CA::Transaction*) + 292
52 QuartzCore                     0x185e5d5f8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
53 QuartzCore                     0x185e5cc94 CA::Context::commit_transaction(CA::Transaction*) + 252
54 QuartzCore                     0x185e5c9dc CA::Transaction::commit() + 512
55 QuartzCore                     0x185e560cc CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
56 CoreFoundation                 0x18371c588 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
57 CoreFoundation                 0x18371a32c __CFRunLoopDoObservers + 372
58 CoreFoundation                 0x18371a75c __CFRunLoopRun + 928
59 CoreFoundation                 0x183649680 CFRunLoopRunSpecific + 384
60 GraphicsServices               0x184b58088 GSEventRunModal + 180
61 UIKit                          0x1884c0d90 UIApplicationMain + 204
62 APP_NAME                       0x100075f08 main (AppDelegate.swift:20)
63 ???                            0x1831ea8b8 (Missing)

1 个答案:

答案 0 :(得分:0)

您只需要通过两种方式之一来注册单元格。因此,您可以保留第二个选项

self.messagesTable.register(UINib(nibName: "MessagesCell", bundle: nil), forCellReuseIdentifier: "MessagesCell")

注释第一行,它将开始工作。

//self.messagesTable.register(MessagesCell.self, forCellReuseIdentifier: "MessagesCell")

要向self.messagesTable.register(MessagesCell.self, forCellReuseIdentifier: "MessagesCell")注册,您还需要添加init(coder:)

尝试并分享您的结果。