I am trying to grab the string off an object in a table row when it is clicked. I have seen tutorials about getting the string and passing it to synthesized label however I am unable to pass the same string to a synthesized string in my modal view. Is this possible? My code in the parent view is as follows.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Modules *selectedModule;
selectedModule = [fixedArray objectAtIndex:indexPath.row];
NSString *moduleComponent = [selectedModule valueForKey:@"name"];
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[self.navigationController pushViewController:detail animated: YES];
detail.number.text = moduleComponent;
detail.moduleLabel.text = moduleComponent;
detail.module = moduleComponent;
}
The detail.moduleLabel.text displays correctly however when I try to alert or draw a label using the detail.module I receive null. Any help is greatly appreciated.
Move [self.navigationController pushViewController:detail animated: YES];
after assigning the value to the detail controller.
EDIT: Another point to note is when exactly do you try to alert it - viewDidLoad, viewWillAppear, viewDidAppear. Try in the different methods to see what the result is. I apologize but I am unable to test it now and give you the result itself, but have experienced similar behavior (not assigned value) depending on the specific event (viewDidLoad, viewWillAppear, viewDidAppear) where I try to access the value.