I have a tableviewcontroller with data population it. I’m trying to get a new details view to be pushed when the user taps on a cell. I can get the view to load, however the labels to show the data in more detail are not updated. Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
SearchDetailViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"searchDetailVC"];
Events *event = [events objectAtIndex:indexPath.row];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
NSString *dateString = [dateFormatter stringFromDate:event.eventDate];
controller.title=event.eventName; //ONLY ONE THAT WORKS!
controller.eventName.text = event.eventName;
controller.eventAddress.text = event.eventAddress;
controller.eventDate.text = dateString;
controller.eventTime.text = event.eventTime;
controller.ratingView.image = [self imageForRating:event.eventRating];
controller.eventDistance.text = @"NOT YET IMPLEMENTED";
[self.navigationController pushViewController:controller animated:YES];
}
The only property that is set is the title of the NavigationController navbar. Am I doing something drastically wrong?
You can’t pass data like this. ViewController.domainField is nil at that time because the view hasn’t loaded yet, and the label/TextField is created when the view loads (via a nib) and not as soon as the view controller object is created.
This code can help you
Likewise, you have to pass all data from one view to another view – you can’t directly assign to controller.