我正在尝试将数据从我的数据库传递到在此函数中实例化的新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];
答案 0 :(得分:1)
当您实例化viewController时,它尚未设置其UI。 因此,在viewController的viewDidLoad callBack触发之前,您将无法与UILabel交互。因此,执行所需操作的最佳方法是设置NSString属性,并在viewDidLoad中将它们设置为UILabel。像这样的东西
@property (nonatomic, strong) NSString *cartAddressText;
/* ... */
然后在viewDidLoad
中- (void) viewDidLoad {
[super:viewDidLoad];
self.cartAddress.text = self.cartAddressText;
/* ... */
}