在我的第一個文件中,我希望能夠獲取對第二個文件的引用並更改它的屬性,這就是我所擁有的。我做了一個類方法來返回引用,但問題是我在方法中得到了一個警告,最重要的是當我做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