gpt4 book ai didi

objective-c - 帮助解决编译器警告 : Initialization from distinct Objective-C type when types match

转载 作者:行者123 更新时间:2023-12-03 21:23:45 25 4
gpt4 key购买 nike

这是我收到编译器警告的函数,我似乎无法弄清楚是什么导致了它。如有任何帮助,我们将不胜感激。

 -(void)displaySelector{
//warning on the following line:
InstanceSelectorViewController *controller = [[InstanceSelectorViewController alloc] initWithCreator:self];
[self.navController pushViewController:controller animated:YES];
[controller release];
}

initWithCreator: 方法的接口(interface)和实现

-(InstanceSelectorViewController*)initWithCreator:(InstanceCreator*)creator;


-(InstanceSelectorViewController*)initWithCreator:(InstanceCreator*)crt{
if (self = [self initWithNibName:@"InstanceSelectorViewController" bundle:nil]) {
creator = crt;
}
return self;
}

最佳答案

我猜这不是您的项目中唯一具有 initWithCreator: 方法的类。一般来说,为 init 方法提供静态类型是一个坏主意。 alloc 返回 id,因此编译器不知道您向其发送 init 方法的对象的类型。如果有多个选择,它通常会猜测错误,并且您会收到所看到的警告。

关于objective-c - 帮助解决编译器警告 : Initialization from distinct Objective-C type when types match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2406199/

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