调用另一个视图控制器的Outlet
嘿伙计们, 我有一个 MapperViewController
@interface MapperViewController : UIViewController <MKMapViewDelegate>
{
MKMapView *mapView;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@end
在 .m 文件中,我可以在创建对象后在 MapView 上添加注释(ofc 我有一个 MyAnnotation 类)
MyAnnotation *and = [[MyAnnotation alloc] init];
and.name = @"name";
and.subtitle = @"subtitle";
and.coordinate = CLLocationCoordinate2DMake(10.123,10.123);
[mapView addAnnotation:and];
我在另一个名为 RootViewController 的类中有另一个对象,我在其中添加了上面的值。(ofc 我有一个 Firma类)
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];
我想做的是调用 [mapView addAnnotation:aFirma];在此视图控制器中。 我在 MapperViewController 中有更多调用“mapView”的函数,所以它必须留在那里。
MB你有人可以帮助我吗 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不尝试使 MKMapView 成为 RootViewController 的成员变量?
或者,也欢迎您在Object-C中设置委托层次结构,以便您的RootViewController和MapperViewController可以以父子方式进行通信。
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.