ios - 如何访问来自不同类 Obj-C 的变量

标签 ios objective-c ios9

<分区>

我有 TableViewController 和 ViewController。

机场.h

@interface Airports : UITableViewController

@property(strong, nonatomic) NSNumber* latitude;
@property(strong, nonatomic) NSNumber* longitude;
@property(strong, nonatomic) NSString* selectedAirportName;

@end

Airports.m

这是一个设置纬度经度selectedAirportName属性的实例。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *airportNames = airportsArray[indexPath.row];
    self.selectedAirportName = [airportNames valueForKey:@"$"];
    NSArray *airportCoordinates = airportsCoordinates[indexPath.row];
    self.latitude = [airportCoordinates valueForKey:@"Latitude"];
    self.longitude = [airportCoordinates valueForKey:@"Longitude"];
}

行选择将用户转发到 ViewController,其中我有一个实例,根据所选行中的信息显示带有标记的 GoogleMap。如何让该实例访问 Airports 类的 latitudelongitudeselectedAirportName 属性?实际上,我想知道如何在 didSelectRowAtIndexPath 实例和 Airports 类之外公开这些属性以与它们一起操作。

我只是个初学者。所以不要开枪:)

最佳答案

您应该创建一个单独的对象,使用谷歌地图将您希望传递给 View Controller 的数据映射到 View Controller ,也许可以将其称为机场之类的东西。

然后,当您从第一个 View Controller (Airports)推送 segue 时,您可以在 prepareforsegue 方法中将此对象传递给 View Controller 。

How to pass prepareForSegue: an object

关于ios - 如何访问来自不同类 Obj-C 的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39253256/

相关文章:

依赖于Web服务的iOS应用程序的数据结构

c++ - 在头文件中声明和初始化常量

ios - 如果用户按下后退按钮,如何调用一些代码

swift - ios9 swift 中的 NSUserDefault 关键编码?

IOS 检查手机语言的最佳和安全方法是什么?

ios9 - iPhone(iOS 9)锁定屏幕上时钟的字体是什么

ios - additionalSafeAreaInsets 的奇怪行为

ios - UIViewController 中的 Collection View 可选展开崩溃

ios - 在模态页面表上呈现模态表单

ios - Xcode UIView rotation : How to set the new position coordinates to 0, 0 旋转后不移动图像?