gpt4 book ai didi

ios - initWithFrame 未在 UIVIew 中执行

转载 作者:行者123 更新时间:2023-11-28 18:00:21 24 4
gpt4 key购买 nike

我创建了一个 UIView 子类并且想在 initWithFrame: 上执行一个方法,但是这个方法没有被调用。

当我从正在执行的 initWithCoder: 调用方法时,代码崩溃并显示此错误:

Terminating app due to uncaught exception 'NSGenericException', reason: 'This coder requires that replaced objects be returned from initialization coder method:'

我的代码是:

-(void)initialize
{
//code
}

-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initialize];

// Initialization code
}
return self;
}

- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];

if(self)
{
[self initialize];
}
return self;
}

最佳答案

您没有从 initWithCoder: 方法返回 self

关于ios - initWithFrame 未在 UIVIew 中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15896855/

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