Ich habe eine UICollectionView
und wenn der Benutzer eine Zelle drückt, präsentiere ich einen anderen View-Controller in einem UINavigationController
modal mit einem Storyboard.segue.destinationViewController ist Null beim Präsentieren von UINavigationController modal
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"editBookIPad"
sender:indexPath];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
// Did not include code for other segues, but I check which is the current one properly
UINavigationController *dest = segue.destinationViewController; // This is nil!
dest.modalPresentationStyle = UIModalPresentationFormSheet;
DetailsViewController *detailsVC = (id)[dest topViewController];
detailsVC.stack = self.stack;
detailsVC.editingMode = 1;
detailsVC.bookToEdit = [self.fetchedResultsController objectAtIndexPath:sender];
[self.collectionView deselectItemAtIndexPath:sender
animated:YES];
}
Nun, mein Problem ist, dass segue.desinationViewController
kehrt nil
(wie der Kommentar im Code-Schnipsel sagt).
Nur zum Debuggen, änderte ich die UINavigationController
zu einem anderen View-Controller und ich hatte kein Problem. Ich weiß nicht, ob der Wechsel von Modal zu Push als Übergangsstil helfen wird, da es unmöglich ist, eine UINavigationController
zu drücken (ein Crash passiert, der sagt, dass es so ist).
Ich bereinigte das Projekt und den Build-Ordner und startete meinen Computer (und damit Xcode) neu.
Dies ist, wie es aussieht, wenn läuft die App:
Wenn für ähnliche Probleme der Suche fand ich nichts. Bei den meisten anderen Fragen ging es darum, dass die Eigenschaften des Ziel-View-Controllers auf Null gesetzt wurden (z. B. this).
Ich benutze Xcode 5.1.1 und habe iOS 7.0 als Entwicklungsziel.
Edit1
Das gleiche Problem tritt in allen Teilen meiner App jetzt (überall ein UINavigationController
modal dargestellt). Allerdings, passiert es nur bei einigen Gelegenheiten, aber jedes Mal segue.destinationViewController
ist immer noch nil
.
EDIT2
Ich ersetzte den prepareForSegue
Code mit diesem (es manuell zu tun):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard"
bundle:nil];
UINavigationController *navCon = [storyboard instantiateViewControllerWithIdentifier:@"AllBooksVCDetails"]; // The problematic navigation controller
navCon.modalPresentationStyle = UIModalPresentationFormSheet;
BKSBookDetailsViewController *detailsVC = (id)[navCon topViewController];
detailsVC.stack = self.stack;
detailsVC.editingMode = 1;
detailsVC.bookToEdit = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self presentViewController:navCon
animated:YES
completion:nil];
[self.collectionView deselectItemAtIndexPath:indexPath
animated:YES];
Und das funktioniert. Also ich denke das Problem liegt irgendwie im Storyboard.
ich meinen Code überprüft, und ich wurde mit ** ** segue. Danke für die Antwort obwohl – user3956212