Ich habe ein UIViewController
namens FriendsViewController
in einem UINavigationController
. Und ein zweites UIViewController
namens FriendsDetailedViewController
. Wenn ich vom ersten zum zweiten Ansichts-Controller navigiere, möchte ich bei Bedarf programmgesteuert die Taste Back
drücken. Wie macht man das?
Einfach benutzen
[self.navigationController popViewControllerAnimated:YES]
von FriendsDetailedViewController. Ihre Ansicht wird hervorgehoben, d. H. Das Verhalten der Zurück-Taste
Wenn Sie mit der Schaltfläche "Zurück" nur zur vorherigen Ansichtssteuerung wechseln möchten, können Sie einfach Folgendes aufrufen:
[self.navigationController popViewControllerAnimated:YES];
Hier ist die Swift Methode
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}
Hier ist, wie ich es in Swift 3 gemacht habe
_ = self.navigationController?.popViewController(animated: true)
_
wird verwendet, um die von XCode generierte hässliche Warnung zu unterdrücken.
1) Wenn Sie den aktuellen NavigationController einblenden, dann
In Swift
self.navigationController?.popViewControllerAnimated(true)
Ziel C
[self.navigationController popViewControllerAnimated:YES];
2) Wenn Sie einen anderen Navigationscontroller unterstützen Dann
In Swift
let story = UIStoryboard(name: "Main", bundle: nil)
let pushVC = story.instantiateViewControllerWithIdentifier("PushVC")
let navigation = story.instantiateViewControllerWithIdentifier("homeNavigation") as! UINavigationController
navigation.pushViewController(pushVC!, animated: true)
In Ziel C
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"storyBoardName" bundle:nil];
pushVC* ObjectOfPushVC = [storyboard instantiateViewControllerWithIdentifier:@"pushVC"];
[self.navigationController pushViewController:ObjectOfPushVC animated:YES];