Call Outlet of another view controller

天大地大妈咪最大 提交于 2019-12-25 04:37:19

问题


Hy Guys, I have a MapperViewController

@interface MapperViewController : UIViewController <MKMapViewDelegate>
{
 MKMapView *mapView;

}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@end

In the .m file I can add annotations on a MapView after creating an object (ofc I have a MyAnnotation class)

MyAnnotation *and = [[MyAnnotation alloc] init];
 and.name = @"name";
 and.subtitle = @"subtitle";
 and.coordinate = CLLocationCoordinate2DMake(10.123,10.123);
 [mapView addAnnotation:and];

I have another object in another class called RootViewController where I added the values above.(ofc I have a Firma class)

    firmenArray = [[NSMutableArray alloc] init];

 Firma * aFirma = [[Firma alloc] init];
 aFirma.title = @"title";
 aFirma.boxOfficeGross = [NSNumber numberWithInt: 200000000];
 aFirma.summary = @"summary";
 aFirma.name = @"name";
     aFirma.subtitle = @"subtitle";
     aFirma.coordinate = CLLocationCoordinate2DMake(10.123,10.123);
 [mapView addAnnotation:aFirma];
 [firmenArray addObject: aFirma];
 [aFirma release];

What I want to do is call the [mapView addAnnotation:aFirma]; within this view controller. I have more functions in the MapperViewController which call "mapView", so it have to stay there.

MB someone of u can help me Thank you


回答1:


Why not try make MKMapView a member variable of your RootViewController?

Or, you are also welcome in Object-C to set a delegate hierarchy so that your RootViewController and MapperViewController can communicate in a parent-child way.



来源:https://stackoverflow.com/questions/4486084/call-outlet-of-another-view-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!