在我的第一个文件中,我希望能够获取对第二个文件的引用并更改它的属性,这就是我所拥有的。我做了一个类方法来返回引用,但问题是我在方法中得到了一个警告,最重要的是当我做if语句它似乎不运行。创建对另一个类的引用,目标C
需要参考,第一个文件调用类的方法获取引用
,我想引用,参考收益使用自-(void) updateSplitViewDetail{
id detail = (MapViewController*) [MapViewController returnReference];
NSLog(@"%@", [detail class]); //This post MAPVIEWCONTROLLER
//This fails so I cant access the methods inside.
if ([detail isKindOfClass:[MapViewController class]]) {
MapViewController *mapVC = (MapViewController*) detail;
mapVC.delegate = self;
mapVC.annotations = [self mapAnnotations];
}
}
(void)viewDidLoad
{
[super viewDidLoad];
[self updateSplitViewDetail]; //Error may be here?
}
第二个文件。
- (void)viewDidLoad
{
NSLog(@"%@", [self class]);
[super viewDidLoad];
self.mapView.delegate = self;
// Do any additional setup after loading the view.
}
+(MapViewController*) returnReference{
//I also get an incompatible pointer return warning here?
return self;
}
所以如果我在第二个文件中创建一个MapViewController财产,通过使返回的参考和实例变量返回它,然后使用第一个文件的MapViewController的一个实例,它应该工作> – 2012-08-15 05:47:10
@TerrelGibson调用它:我不知道真的明白你在说什么。但'+ returnReference'是一个类方法,它只是一个类的方法。这不是一个实例的方法。如果你试图在一个实例上调用'returnReference',它将不会工作,因为没有'-returnReference'。 – newacct 2012-08-15 09:38:51
如果我更改+ returnReference到-ReturnReference? – 2012-08-15 18:12:50