如何在iOS中将数据从容器发送到父视图控制器?
2019年06月30日
作者:佚名
参见英文答案 >
Passing Data between View Controllers41个
我正在尝试将数据从容器(子视图)发送到父级.在另一个视图控制器中,我能够使用从父级向子级发送数据
我正在尝试将数据从容器(子视图)发送到父级.在另一个视图控制器中,我能够使用从父级向子级发送数据
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
但是,我不确定如何将数据从子节点发送到父节点,特别是我正在尝试将属性userLat(它是容器的属性)发送给父节点.有什么建议?
PinViewController.m(父):
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSLog(@"children : %@",self.childViewControllers); //this returns the child view controller NSLog(@"children : %@",self.childViewControllers.userLat); //userLat is a property of the child view controller,but displays an error in Xcode. }
MapWithinPinViewController(子,容器)
- (void)viewDidLoad { GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView_.myLocationEnabled = YES; mapView_.delegate = self; self.view = mapView_; } - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate { NSLog(@"You tapped at %f,%f",coordinate.latitude,coordinate.longitude); [mapView_ clear]; GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude); self.userLat = @"test"; marker.map = mapView_; }
解决方法
Apple建议您在prepareForSegue中将父级设置为子级的委托.然后,子进程可以使用委托方法(自定义协议)与父进行通信.
以上是来客网为你收集整理的如何在iOS中将数据从容器发送到父视图控制器?全部内容,希望文章能够帮你解决如何在iOS中将数据从容器发送到父视图控制器?所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。