ios UIView 没有初始化调用

标签 ios

我当前的 Storyboard布局

UIViewController
  |
  +- UIView (MyView)

MyView 中,我构建了以下函数

  • 初始化
  • 初始化框架
  • 初始化代码
  • 从 Nib 醒来
  • awakeAfterUsingCoder

在这五个中,只有两个实际运行

  • 从 Nib 醒来
  • awakeAfterUsingCoder

我搜索了一段时间,但无法弄清楚为什么 init 函数不起作用。

最佳答案

根据我在顶部的评论:

@MichaelDautermann 这很简单。现在已经连续两天了。我有 - (id)initWithCoder:(NSCoder *)aDecoder:(CGRect)frame。为什么我花了这么长时间才看到这些 n00b 错误?我不知道。在我看来,Xcode 没有给我任何构建错误。

我的代码不正确:

- (id)initWithCoder:(NSCoder *)aDecoder:(CGRect)frame {
    if(self = [super initWithCoder:aDecoder]) {
        //
    }
    return self;
}

正确代码:

- (id)initWithCoder:(NSCoder *)aDecoder {
    if(self = [super initWithCoder:aDecoder]) {
        //
    }
    return self;
}

关于ios UIView 没有初始化调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9011493/

相关文章:

ipad - UIActionSheet Controller在iPad上崩溃,在iPhone上运行正常

ios - Objective-C:有哪些设计模式可以将模型与从属性列表中选择的 View 联系起来?

iOS View 就像 Facebook 应用程序中一样

android - 与 Android 和 iOS 进行 Azure 服务总线消息传递

ios - 无需自定义方案即可深层链接至 iPhone 应用程序

ios - 为什么使用协议(protocol),而不是直接调用方法?

ios - 使用UILongPressGestureRecognizer检测左右移动吗?

ios - 如何在 SwiftUI 中淡化 SF 符号的顶部或底部边缘?

ios - ViewController 加载两次

ios - 使用 "init"或 "didmove"的正确方法是什么?