代码之家  ›  专栏  ›  技术社区  ›  Alex Gosselin

编译器警告帮助:类型匹配时从不同的objective-c类型初始化

  •  2
  • Alex Gosselin  · 技术社区  · 16 年前

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

     -(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;
    }
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Chuck    16 年前

    我猜这不是你项目中唯一有 initWithCreator: 方法。一般来说,给in it方法提供静态类型是一个坏主意。 alloc 收益率 id ,所以编译器不知道要向其发送init方法的对象的类型。如果有不止一个选择,它往往会猜错,你会得到你看到的警告。