UITextView _firstBaselineOffsetFromTop中的断言失败 [英] Assertion failure in UITextView _firstBaselineOffsetFromTop

查看:299
本文介绍了UITextView _firstBaselineOffsetFromTop中的断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在了解Xcode中的查看调试器并使用以下方式捕获视图层次结构调试>查看调试>捕获视图层次结构。但是,当我在我的应用程序中尝试它时,我收到以下错误:

I was learning about the view debugger in Xcode and capturing the view hierarchy with Debug > View Debugging > Capture View Hierarchy. However when I tried it in my app I got the following error:


断言失败 - [UITextView _firstBaselineOffsetFromTop],/ BuildRoot / Library / Caches / com.apple.xbs / Sources / UIKit_Sim / UIKit-3512.60.7 / UITextView.m:1683

Assertion failure in -[UITextView _firstBaselineOffsetFromTop], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITextView.m:1683

我可以重现这个在以下简单项目中:

I could reproduce this in the following simple project:

import UIKit
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let myTextView = UITextView()
        myTextView.frame = CGRect(x: 50, y: 50, width: 200, height: 100)
        myTextView.text = "This is a test."
        view.addSubview(myTextView)

    }
}

我看到此处可能是由于未使用自动布局造成的。这真的是一个我们必须等待修复的错误吗?是否有Swift解决方法?

I saw here that it could be caused by not using auto layout. Is this really a bug that we have to wait for a fix? Is there a Swift workaround?

更新

建议的副本看起来像同样的问题我有。但是,与该问题不同,我要求Swift解决方法。这个问题的答案只是一个链接(我上面已经有过的链接)。我投票以另一种方式关闭。

The suggested duplicate looks like the same issue I am having. However, unlike that question, I am asking for a Swift workaround. The "answer" to that question was just a link (the same link that I already had above). I am voting to close the other way.

推荐答案

注意仅在DEBUG构建中执行此操作

Note do this in DEBUG builds only

解决此问题的解决方法。在项目中保持以下类别。它对我有用。

A workaround to resolve this issue. Keep below category in your project. It worked for me.

@interface UITextView(MYTextView)

@end

@implementation UITextView (MYTextView)
- (void)_firstBaselineOffsetFromTop {

}

- (void)_baselineOffsetFromBottom {

}

@end

对于swift

extension UITextView {
    func _firstBaselineOffsetFromTop() {
    }
    func _baselineOffsetFromBottom() {
    }
}

这篇关于UITextView _firstBaselineOffsetFromTop中的断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆