问题
I have lots of rows in the Master, the first time I click a row, the content is displayed in Details. I go back, choose a new row, or the same row, it displays "Detail view content goes here" in Details. I've traced like crazy, used NSLog just in case it's some kind of event reordering, used setNeedsDisplay in the view and in the UIControl instance. Everything is tracking out okay in the right order, but nothing is displaying the new content. NSLog shows the new content is in the control, just not being displayed. Any assistance would be welcome, this is driving me crazy.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow];
NSObject *object = [[[self objects] objectAtIndex:[indexPath section]] objectAtIndex:[indexPath row]];
[[segue destinationViewController] setDetailItem:object];
}
}
回答1:
I am updating by sending a message to the sender. I had included code to set the sender, e.g. the detail view, but assumed it wouldn't be changed after it was set. It turns out detail views are created new each time so the previous link would be invalid. Fixed it by simply resaving the sender every time the view is constructed.
来源:https://stackoverflow.com/questions/13084561/ios-master-detail-app-detail-shows-only-the-first-time