I have a UISplitViewController in which i’m attempting to pass an int value from the MasterViewController to a DetailTableViewController. Both the master and the detail view controller are UITableViewControllers. I am attempting to pass the indexPath.row value from the master to the detail which will dictate which array of objects is loaded into the detailViewController’s tableview.
Some code from MasterViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int indexRowTouched = indexPath.row;
detailViewController = [self.splitViewController.viewControllers lastObject];
NSLog(@"%@", detailViewController);
detailViewController.detailItem = indexRowTouched;
NSLog(@"index row %i", indexRowTouched);
}
An exception is thrown here
detailViewController.detailItem = indexRowTouched;
2012-03-28 16:08:19.625 splittest2[14895:f803] -[UINavigationController setDetailItem:]: unrecognized selector sent to instance 0x6b592e0
From the DetailViewController.m
- (void)setDetailItem:(int)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
I also note that the value of detailItem logs “0” as soon as the detailView is loaded, before an indexPath row is selected at all.
Im wondering why this property is not being assigned from the MasterViewController, and the TableView is not being updated.
EDIT
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int indexRowTouched = indexPath.row;
detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
detailViewController.detailItem = indexRowTouched;
NSLog(@"index row %i", indexRowTouched);
}
Trying to access the setDetailItem on the UINavigationController seems to have been fixed by changing the didSelectRowAtIndexPath to the above
In your
- (void)configureViewfunction, you are doingSince
detailItemis anint, not an object, if it is equal to 0,if (detailItem)will return false. Thus if you are sending 0 todetailItem, yourconfigureViewif statement will not be entered and nothing will happen.You should remove that outside if statement entirely and just have: