Я все еще новичок в этом материале Objective 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
Как мне получить доступ к объекту mapView на Class1? Нужно ли создавать экземпляр класса 1 для доступа к свойству?
Спасибо