为什么找不到我的方法?

时间:2011-05-02 06:10:05

标签: objective-c

我的SecondViewController : UIViewController

有自定义初始化方法
-(id) initWithFirstViewController:(FirstViewController *)theFirstViewController
{
    self = [super init];

    fvc = theFirstViewController;     

    return self;   
}

所以在我的FirstViewController中,我使用FirstViewController的实例作为参数调用此init方法。 SecondViewController中的其他地方我使用了这个传递的内容:

[fvc setSomething];

该方法已执行,但我收到警告:

  

找不到方法-setSomething(返回类型默认为id

如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

在这种情况下,这是#import相应的.h文件的问题,因此编译器知道该方法。

此外,您应该保留theFirstViewController,因为它可能会被释放,并且在完全相同的内存位置(fvc仍然指向的位置)创建了不同的对象。所以你应该做fvc = [theFirstViewController retain];,因为你正在“坚持”第一个视图控制器(你想稍后再使用它)。不要忘记在dealloc

中发布它