Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS11以下崩溃 #22

Open
IAFung opened this issue Jan 4, 2021 · 3 comments
Open

iOS11以下崩溃 #22

IAFung opened this issue Jan 4, 2021 · 3 comments

Comments

@IAFung
Copy link

IAFung commented Jan 4, 2021

在iOS11以下的系统,kvo的监听会崩溃,An instance 0x7f9395d49750 of class SXLabel was deallocated while key value observers were still registered with it. Current observation info:
使用了textView的attachment
attributed.text = .init("\(.view(customLabel, .original(.center))) \(string)", .paragraph(.lineSpacing(7)))

@lixiang1994
Copy link
Owner

我换电脑了 现在没有iOS11以下的环境, 能发一些详细的截图吗? 这个问题可以稳定复现吗?

@IAFung
Copy link
Author

IAFung commented Jan 6, 2021

稳定复现,使用kvo的keypath的方式在iOS11以下好像要手动调用invalidate释放
调用代码

class SXTextView: UITextView {
    private let customLabel = UILabel()
    @objc var string: String? {
        didSet {
            customLabel.text = "交易备注"
            customLabel.font = .systemFont(ofSize: 12)
            customLabel.backgroundColor = #colorLiteral(red: 0.9098039216, green: 0.2078431373, blue: 0.1333333333, alpha: 0.1004120291)
            customLabel.textColor = #colorLiteral(red: 0.9098039216, green: 0.2078431373, blue: 0.1333333333, alpha: 1)
            customLabel.textAlignment = .center
            customLabel.frame = CGRect(x: 0, y: -3, width: 58, height: 23)
            isEditable = false
            isSelectable = false
            attributed.text = .init("\(.view(customLabel, .original(.center)))    \(string!)", .paragraph(.lineSpacing(7)))
            attributed.layout()
        }
    }
    @objc func layout() {
        attributed.layout()
    }
}
let textView = SXTextView()
textView.string = "qeqewqkqwkjrqwjrkjqjnsdnfajsnfieuwrhweirhiuweqweqwe"
 view.addSubview(textView)

每次调用的页面释放时,崩溃信息如下:

2021-01-06 10:36:55.640 XibTest[14529:1236068] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7ffa900ffe00 of class XibTest.SXTextView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x618000039c20> (
<NSKeyValueObservance 0x61800005a190: Observer: 0x618000059d40, Key path: bounds, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x618000059830>
<NSKeyValueObservance 0x61800005a4c0: Observer: 0x61800005a520, Key path: frame, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x61800005a580>
)'

@lixiang1994
Copy link
Owner

你好, 还存在这个问题吗? 抱歉 过这么久才看到你的回复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants