I have two TableViewControllers with a segue in-between. When a user clicks on a cell in the first TVC they get presented with the second TVC. The segue is modal, has an identifier called "segueToLocationDetails" and passes an object along with it. You can think of the second TVC as a "details" page more or less.
My code works perfectly in the scenario that I've described above. It breaks however as soon as I embed the second TVC into a navigation controller.
Example. I have it working perfectly. I then highlight the second TVC in IB, mouse over to Product | Embed in | Navigation controller. Now the second TVC is in a Nav Controller. The segue however still points to the second TVC. I remove the segue and reconnect it from the first TVC's cell to the Navigation Controller and be sure give the segue an identifier. Run again, and it breaks! The error is below...
2011-12-23 15:30:45.469 Project12[5219:11603] -[UINavigationController setDetailsObject:]: unrecognized selector sent to instance 0x7b92ce0 2011-12-23 15:30:45.471 Project12[5219:11603] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setDetailsObject:]: unrecognized selector sent to instance 0x7b92ce0' * First throw call stack: (0x16ea052 0x150ad0a 0x16ebced 0x1650f00 0x1650ce2 0x3933 0x703e1e 0x36f6d9 0x36f952 0xbf786d 0x16be966 0x16be407 0x16217c0 0x1620db4 0x1620ccb 0x14ec879 0x14ec93e 0x2dfa9b 0x2a98 0x29f5 0x1) terminate called throwing an exceptionCurrent language: auto; currently objective-c
Some code is below to help explain:
AllLocations.h & AllLocations.m (this is the master table)
AllLocations.h
@interface AllLocations : UITableViewController
{
SQLiteDB *mySQLiteDB;
}
@property (nonatomic, strong) NSMutableArray *locationsArray;
AllLocations.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"segueToLocationDetails" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"segueToLocationDetails"])
{
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
NSInteger rowNumber = selectedIndexPath.row;
mySQLiteDB = (SQLiteDB *) [locationsArray objectAtIndex:rowNumber];
DetailsTVC *detailsTVC = [segue destinationViewController];
detailsTVC.detailsObject = mySQLiteDB;
}
}
DetailsTVC.h & DetailsTVC.m (this is the detailed table view)
DetailsTVC.h
@interface DetailsTVC : UITableViewController
@property (nonatomic, strong) SQLiteDB *detailsObject;
DetailsTVC.m
@implementation SpotDetailsTVC
@synthesize spotDetailsObject;
Note: I left out all of the code that was not really important or relevant to the question.
Again: This works perfectly if the segue goes from the Originating TableVeiwController to the other TableViewController. It only breaks when I embed the second TVC in a Nav Controller. I need to know how to get this working with the Nav Controller in the picture. Thanks in advance!
DetailsTVC *detailsTVC = [segue destinationViewController];
That line is incorrect. Since your second TVC is now embedded in a navigation controller, [segue destinationViewController] is now a UINavigationController. This should work:
DetailsTVC *detailsTVC = [[segue destinationViewController] visibleViewController];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With