gpt4 book ai didi

objective-c - 调用 initWithNibName 时 "The result of a delegate init call must be immediately returned or assigned to ' self '"

转载 作者:行者123 更新时间:2023-12-02 21:49:58 29 4
gpt4 key购买 nike

由于某种原因,我无法调用 initWithNibName 方法并收到错误消息:“必须立即返回委托(delegate) init 调用的结果或将其分配给‘self’”。这是 ARC 的一些额外功能吗,因为如果不指定 Nib 名称,我就无法初始化 View 。

这是我在 .m 文件中的代码:

#import "SimpleMotionControllerIntroduction.h"

@implementation SimpleMotionControllerIntroduction

-(id) init
{
self = [super init];

if (self)
{
[self initWithNibName:@"SimpleMotionIntroductionView" bundle:nil];
}

return self;
}

@end

我觉得我犯了某种粗心的错误,我以前使用过 iOS 5,并制作了一个像这样的应用程序,其工作方式相同。提前致谢。

最佳答案

两个粗心错误:您正在调用两个 init 方法 (1),并且忽略第二个方法的结果(2,触发错误消息)。

永远不应该对一个对象进行两次 init 调用。请注意,initWithNibName 也会调用 init。我认为这实际上会导致无休止的递归并最终导致堆栈溢出。

关于objective-c - 调用 initWithNibName 时 "The result of a delegate init call must be immediately returned or assigned to ' self '",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9449549/

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