gpt4 book ai didi

ios - 点击 UITextField 或 UITextView 时崩溃 : Assertion failure in -[UICalloutBarButton layoutSublayersOfLayer:]

转载 作者:行者123 更新时间:2023-11-29 12:32:04 30 4
gpt4 key购买 nike

类似问题的答案没有帮助,所以我提出了一个新问题。

我现在在我的几个项目中都遇到了这个问题:

点击第一响应者 UITextFieldUITextView(通常会调出用于复制和粘贴的默认上下文菜单)会导致我的应用程序崩溃.

注意 UICalloutBarButton 是一个UIKit 私有(private)API,所以没有机会改变它的layoutSubviews 实现并在其中调用 [super layoutSubviews]

日志消息:

*** Assertion failure in -[UICalloutBarButton layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8794
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UICalloutBarButton's implementation of -layoutSubviews needs to call super.'

我不知道为什么会出现这种情况。非常乐意提供任何帮助。


编辑

尝试在演示项目中重现崩溃,我发现是自定义 UIView 类别导致了崩溃。有关详细信息,请参阅已接受的答案。


最佳答案

通过尝试在演示项目中重现崩溃,我发现它是导致崩溃的自定义 UIView 类别。

创建此错误时,我假设类别方法仅适用于 #import 此类别的 UIView 子类。

但事实并非如此 Apple Documentation :

Any methods that you declare in a category will be available to all instances of the original class, as well as any subclasses of the original class. At runtime, there’s no difference between a method added by a category and one that is implemented by the original class.

所以没有意识到这一点,我在我的自定义类别中覆盖了 UIView 方法 + (BOOL) requiresConstraintBasedLayout 以返回 YES (就像我错误地认为只针对那些导入该类别的类)。

在那个方法中放置一个断点,我了解到一旦将类别文件添加到项目中,就会从 UIKit 中的任何地方调用这个“类别方法”。

不过是一种痛苦的学习/接受方式,覆盖类别中的方法永远不是一个好主意 - 除非你想造成像这样的奇怪崩溃;-)。

很抱歉耽误了您的时间,但感谢您询问了一些代码示例,这些示例迫使我认真地重现了这个问题——这导致了我的崩溃原因……

关于ios - 点击 UITextField 或 UITextView 时崩溃 : Assertion failure in -[UICalloutBarButton layoutSublayersOfLayer:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27405915/

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