Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将数据从ViewController传递到实例化的自定义ViewController_Ios_Objective C_Viewcontroller - Fatal编程技术网

Ios 将数据从ViewController传递到实例化的自定义ViewController

Ios 将数据从ViewController传递到实例化的自定义ViewController,ios,objective-c,viewcontroller,Ios,Objective C,Viewcontroller,我试图将数据从数据库传递到这个函数中实例化的新viewcontroller中的UILabels中。我已经测试了数据是否被正确抓取,并且工作正常 我认为我没有为实例化正确引用DataViewController中的UILabel。当我尝试NSLog(dataViewController.cartAddress)时,得到的是空值 有什么帮助吗 ViewController.m - (void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarke

我试图将数据从数据库传递到这个函数中实例化的新viewcontroller中的UILabels中。我已经测试了数据是否被正确抓取,并且工作正常

我认为我没有为实例化正确引用DataViewController中的UILabel。当我尝试NSLog(dataViewController.cartAddress)时,得到的是空值

有什么帮助吗

ViewController.m

- (void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:    (GMSMarker *)marker {
NSObject_DatabaseHelper *dataToPush = [NSObject_DatabaseHelper getSharedInstance];
NSArray *cartDataToPush = [dataToPush findByName:marker.title];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
DataViewController *dataViewController = (DataViewController *)[storyboard instantiateViewControllerWithIdentifier:@"dataViewController"];

dataViewController.cartAddress.text = cartDataToPush[0];
dataViewController.thumbsUp.text = cartDataToPush[3];
dataViewController.thumbsDown.text = cartDataToPush[4];
dataViewController.pitaBool.text = cartDataToPush[5];
dataViewController.drinkBool.text = cartDataToPush[6];
dataViewController.greenSauceBool.text = cartDataToPush[7];


[self.navigationController pushViewController:dataViewController animated:YES];

实例化viewController时,它尚未设置其UI。 因此,在启动viewController的viewDidLoad回调之前,您将无法与UILabel交互。因此,最好的方法是设置NSString属性,并在viewDidLoad中将它们设置到UILabels中。诸如此类

@property (nonatomic, strong) NSString *cartAddressText;
/* ... */
然后在viewDidLoad中

- (void) viewDidLoad {
     [super:viewDidLoad];
     self.cartAddress.text = self.cartAddressText;
     /* ... */
}

新VC的UI元素在VC出现之前(即将其推到导航控制器上之后)不会加载。在
DataViewController
中定义
NSString
属性,并在上面的方法中设置这些属性,然后在
viewdiload
中将UILabel文本设置为属性值。感谢提供此信息!我能够将数据发送到DataViewController,并在viewDidLoad方法中设置字段。