Matthew Evans Matthew Evans - 4 months ago 10
Objective-C Question

How to pass information from Table View to Detail View

First, thanks in advance!
Second, I have googled and checked forums for an answer that helps, but couldn't find anything that helped. I know it is an area that is asked a lot.

So I am trying to push information to a Detail view controller from a Table View. The information is on a plist. The tutorial I used to get this code is old and uses xibs. Using storyboards, it throws the error below:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:


I know that this is because I do not have a xib file named 'DetailViewController'. I want this (and the information from the plist) to be pushed to my "DetailViewController", which is in my storyboard but I can not find the code required to do so.

Could you please help me with this? What changes do I need to make?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row];
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
}
self.detailViewController.detailItem = BibleVerses;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

Answer

if your controller is in storyboard, you can use instantiateViewControllerWithIdentifier method.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row];
if (!self.detailViewController) {
    self.detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
}
self.detailViewController.detailItem = BibleVerses;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}