我想将数据从MainViewController传递给特定的(这取决于用户在GoogleMap中的选择)视图控制器。在MainVC中,我有NSArray,它被称为:userData。 代码是:
NSDictionary *tempDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"FirstViewController", @"First",
@"SecondViewController", @"Second",
nil];
NSString *viewControllerIdentifier = [tempDictionary valueForKey:[marker.userData valueForKey:@"controller"]];
UIViewController *destViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:viewControllerIdentifier];
//destViewController.placeData = marker.userData;
[self.navigationController pushViewController:destViewController animated:YES];
//destViewController.placeData = marker.userData;
不存在。
我应该在UIViewController实现中添加这个NSArray吗?还是有什么想法?
谢谢Artem:)
答案 0 :(得分:0)
如果你确定,你的故事板中的viewController实例化可以处理这些数据,只需创建自己的ViewController类来管理这个NSArray
@interface MyViewController : UIViewController
@property (nonatomic, strong) NSArray placeData;
@end
并在您的示例代码中:
NSDictionary *tempDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"FirstViewController", @"First",
@"SecondViewController", @"Second",
nil];
NSString *viewControllerIdentifier = [tempDictionary valueForKey:[marker.userData valueForKey:@"controller"]];
MyViewController *destViewController = (MyViewController *)[iPhoneStoryboard instantiateViewControllerWithIdentifier:viewControllerIdentifier];
destViewController.placeData = marker.userData;
[self.navigationController pushViewController:destViewController animated:YES];
完成此操作后,所有viewControllers(假设有超过1个)都可以将此作为母类使用