【问题标题】:super initWithFrame returned nil from -traitCollection, which is not allowedsuper initWithFrame 从 -traitCollection 返回 nil,这是不允许的
【发布时间】:2021-08-10 14:24:09
【问题描述】:

我正在 XCode 12.0 上运行我的 Objective-C 项目之一。我有 UIControl 子类“SeatingPanelControl”,从中创建了另一个名为“IpadSeatingPlanControl”的子类,其中我在执行以下代码时遇到了崩溃,但标题中提到了异常(也在屏幕截图中给出):

//IpadChamberViewController.m
self.seatingPlanControl = [[[IpadSeatingPlanControl alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * 4/7,[self.view bounds].size.width,[self.view bounds].size.height * 3/7 + 20.0)] autorelease];

更新(解决方案):

我找到了问题的原因。在修复 XCode 12 的 IMP 问题时,我错误地删除了一行代码。根据当前的代码设置,它在 iPhone 上运行良好,但在 iPad 上运行不正常。恢复这行代码解决了这个问题。

【问题讨论】:

  • 请提供更多代码
  • 你没有提到这个 IpadChamberViewController。它的初始化器返回 nil。

标签: ios objective-c uitraitcollection initwithframe


【解决方案1】:

检查您的IpadChamberViewController 在他的初始化程序中调用[super init...]

【讨论】:

  • 对不起,我错过了完整的细节。请检查我编辑的问题和更新的屏幕截图。 IpadSeatingPlanControl 是 SeatingPlanControl 的子类,SeatingPlanControl 是 UIControl 的子类。
  • @iAkshay 看起来问题出在IpadSeatingPlanControl initWithFrame,显示其代码
  • IpadSeatingPlanControl 没有 initWithFrame 方法。只有一种方法:drawRect()。因此,当我调用 IpadSeatingPlanControl initWithFrame 时,调用了来自 SeatingPlanControl 的相同方法。
  • @iAkshay 好的,你能证明是 IpadChamberViewController init 用于创建它的方法吗?根据崩溃日志它有问题
  • 我想通了,缺少一行代码,被误删了。非常感谢您的宝贵时间和热心帮助。
猜你喜欢
  • 1970-01-01
  • 2020-02-04
  • 2011-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
  • 1970-01-01
相关资源
最近更新 更多