Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译器警告帮助:当类型匹配时,从不同的Objective-C类型初始化_Objective C_Iphone_Oop_Compiler Warnings - Fatal编程技术网

编译器警告帮助:当类型匹配时,从不同的Objective-C类型初始化

编译器警告帮助:当类型匹配时,从不同的Objective-C类型初始化,objective-c,iphone,oop,compiler-warnings,Objective C,Iphone,Oop,Compiler Warnings,这是我得到编译器警告的函数,我似乎不知道是什么导致了它。感谢您的帮助 -(void)displaySelector{ //warning on the following line: InstanceSelectorViewController *controller = [[InstanceSelectorViewController alloc] initWithCreator:self]; [self.navController pushViewControlle

这是我得到编译器警告的函数,我似乎不知道是什么导致了它。感谢您的帮助

 -(void)displaySelector{
    //warning on the following line:
    InstanceSelectorViewController *controller = [[InstanceSelectorViewController alloc] initWithCreator:self];
    [self.navController pushViewController:controller animated:YES];
    [controller release];
}
initWithCreator:方法的接口和实现

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


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

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

我记得出现此错误,问题是我没有导入所需的头文件。谢谢,这正是问题所在。基于您的回答,我的修复方法是在调用initWithCreator:InstanceCreatorViewController控制器=[(InstanceCreatorViewController)[InstanceCreatorViewController alloc]initWithCreator:self]时强制转换类型;该演员阵容中有一个星号,不知道它去了哪里。@Alex Gosselin:Stack Overflow使用Markdown,它解析星号之间的文本,如强调的那样。要正确格式化代码,请将其放在反勾号之间。因此它将是(backtick)
InstanceCreatorViewController*控制器=[(InstanceCreatorViewController*)[InstanceCreatorViewController alloc]initWithCreator:self](反勾)。哈哈,我的朋友,你有所有的答案。