共享对象我还是在这个目标C新的东西,我尝试使用面向对象编程(OOP)清理我的代码。我无法共享的对象是在我第一类中创建我的第二类:目标C:与其他类
Class1.h
@interface Class1ViewController : UIViewController {
IBOutlet RMMapView *mapView;
}
@property (nonatomic, retain) RMMapView *mapView;
@end
我本来在Class1.m这个功能,我想移动到Class2.m和清理代码:
@implementation Marker
- (void)addMarker:(NSInteger)lat:(NSInteger)lon{
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"marker-red" ofType:@"png"];
UIImage *imgLocation = [[UIImage alloc] initWithContentsOfFile:fileLocation];
RMMarker *markerCurrentLocation = [[[RMMarker alloc] initWithUIImage:imgLocation] autorelease];
markerCurrentLocation.zPosition = -1.0;
CLLocationCoordinate2D startingPoint;
startingPoint.latitude = lat;
startingPoint.longitude = lon;
//This line I'm having trouble with, the mapView object from Class1
[mapView.contents.markerManager addMarker:markerCurrentLocation AtLatLong:startingPoint];
[markerCurrentLocation release];
[imgLocation release];
markerCurrentLocation = nil;
}
@end
我如何访问Class1上的对象mapView?我是否需要实例化Class 1以访问该属性? 谢谢
MapView的是1类的一个实例变量。这意味着除非存在实例,否则它不存在。 –