另一个视图控制器的呼叫出口 [英] Call Outlet of another view controller

查看:174
本文介绍了另一个视图控制器的呼叫出口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy Guys,
我有一个MapperViewController

Hy Guys, I have a MapperViewController

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

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

在.m文件中,我可以在MapView上添加注释object(ofc我有一个MyAnnotation类)

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];

我在另一个类中有另一个对象,名为RootViewController,其中我添加了上面的值。 Firma类)

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];

我想要做的是调用[mapView addAnnotation:aFirma];在此视图控制器内。
我在MapperViewController中有更多的函数调用mapView,所以它必须留在那里。

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有人可以帮助我
谢谢

MB someone of u can help me Thank you

推荐答案

为什么不试试让MKMapView成为您的RootViewController的成员变量?

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

或者,您也欢迎在Object-C中设置一个委托层次结构,以便您的RootViewController和MapperViewController可以以父子方式进行通信。

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.

这篇关于另一个视图控制器的呼叫出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆