모바일개발(Mobile Dev)/IOS개발(ObjectC)
couldn't use prepareForSegue to send some viewcontroller with navigation controller
테크한스
2015. 12. 14. 23:02
반응형
to send some viewcontroller with navigation controller,
you can not send with DetailViewController2 *destViewController = segue.destinationViewController (X)
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowDetails"]) {
// [segue returns a UINavigationController and the controller you
// want is embedded in the navigation controller
UINavigationController *navigationController = [segue destinationViewController];
// We want the top view controller from the navigationController
// and don't forget the cast
DetailViewController2 *detailViewController = (DetailViewController2 *)navigationController.topViewController;
// Removed redundant line as there was no need to create local variable for
// one time use
NSUInteger row = [[self.tableView indexPathForSelectedRow] row];
// There was no need to have these two on on separate lines
GameInfo *gameInfoObject = [GamesInfoArray objectAtIndex:row];
// To add a fail safe you could wrap this in respondsToSelector
// just in the event that the topViewController isn't a DetailViewController2
if ([detailViewController respondsToSelector:@selector(setDetailArray:)]) {
// Note the lowercase for detailArray see comments above this property.
detailViewController.detailArray = @[gameInfoObject.HomeTeam, gameInfoObject.AwayTeam];
}
}
}
반응형