【发布时间】:2017-01-08 06:13:33
【问题描述】:
我有 TableViewController 和 ViewController。
Airports.h
@interface Airports : UITableViewController
@property(strong, nonatomic) NSNumber* latitude;
@property(strong, nonatomic) NSNumber* longitude;
@property(strong, nonatomic) NSString* selectedAirportName;
@end
Airports.m
这是一个设置 latitude、longitude 和 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 类中的 latitude、longitude 和 selectedAirportName 属性?实际上,我想知道如何将这些属性公开,以便在 didSelectRowAtIndexPath 实例和 Airports 类之外对其进行操作。
我只是一个初学者。所以不要拍我:)
【问题讨论】:
-
关于这个话题有很多问题。寻找通过 segues 传递的数据。
-
这可能是 iOS 标签中最常见的问题(参见此处,也可参见 stackoverflow.com/a/9736559/294949)。我会要求其他人在这里给出答案和链接,以考虑 为什么 它经常被询问和重新询问。我认为原因是给出的答案往往是关于 vc 通信的特定机制,而对于 iOS 中实践的 MVC 的想法还不够。
标签: ios objective-c ios9