Reputation: 339
I am trying to pass in data from my database into UILabels in a new viewcontroller instantiated in this function. I have tested to see if the data is being grabbed correctly, and that is working fine.
I believe I am not referencing the UILabels in my DataViewController correctly for the instantiation. I am getting null values when I try to NSLog (dataViewController.cartAddress)
Any help?
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];
Upvotes: 2
Views: 90
Reputation: 51
When you instantiate viewController, it hasn't setup its UI. Therefore you won't be able to interact with your UILabel before viewDidLoad callBack of your viewController has fired. So, the best way to do what you want is to set NSString properties and in viewDidLoad set them into UILabels. Something like that
@property (nonatomic, strong) NSString *cartAddressText;
/* ... */
And then in viewDidLoad
- (void) viewDidLoad {
[super:viewDidLoad];
self.cartAddress.text = self.cartAddressText;
/* ... */
}
Upvotes: 1