如何打开新视图并杀死实际视图?
How to open a new view and killed the actual one?
我有两个视图,actualView 和 nextView。实际上在 actualView 中,我想打开 nextView 并传递一些属性(例如 nextView.date = actualView.date)并杀死 actualView。
我想知道是否可行?
我使用了那个代码:
NSLog(@"Views : %@",self.navigationController.viewControllers);
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FormViewController *formView = (FormViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"formView"];
formView.delegate = self;
[self presentViewController:formView
animated:YES
completion:nil];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
当我在这个 "actualView" 中使用 self.navigationController.viewControllers 时,它知道它在哪里 : ,
但是当我在 actualView 中使用 self.navigationController.viewControllers 时,它是 (null)...
那么代表可能有问题吗?
中关于 removeFromSuperview()
的内容
您可以使用模式转场。
这样,当您移动到 nextView 时,actualView 将被释放。
您可以将两个视图与当前模态转接连接起来,这将终止实际视图并转到下一个视图。
这里解释得很好 https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/StoryboardSegue.html
至于将值从一个视图传递到另一个视图,请查看此函数:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
if (segue.identifier == "segue identifier connecting the 2 views") {
let viewController = segue.destinationViewController as! UINavigationController
let detailview = viewController.topViewController as! nextViewViewController
detailview.element defined in nextview = value to send
}
您可以在网上找到很多使用标识符执行 segue 的示例。这是一个很常见的问题。
我找不到比这更简单的方法了:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController *sourceViewController = self;
UIViewController *destinationController = [mainStoryboard instantiateViewControllerWithIdentifier: @"View3"];
UINavigationController *navigationController = sourceViewController.navigationController;
// Pop to root view controller (not animated) before pushing
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:destinationController animated:YES];
我有两个视图,actualView 和 nextView。实际上在 actualView 中,我想打开 nextView 并传递一些属性(例如 nextView.date = actualView.date)并杀死 actualView。
我想知道是否可行?
我使用了那个代码:
NSLog(@"Views : %@",self.navigationController.viewControllers);
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FormViewController *formView = (FormViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"formView"];
formView.delegate = self;
[self presentViewController:formView
animated:YES
completion:nil];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
当我在这个 "actualView" 中使用 self.navigationController.viewControllers 时,它知道它在哪里 : , 但是当我在 actualView 中使用 self.navigationController.viewControllers 时,它是 (null)... 那么代表可能有问题吗?
removeFromSuperview()
的内容
您可以使用模式转场。 这样,当您移动到 nextView 时,actualView 将被释放。
您可以将两个视图与当前模态转接连接起来,这将终止实际视图并转到下一个视图。 这里解释得很好 https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/StoryboardSegue.html
至于将值从一个视图传递到另一个视图,请查看此函数:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){
if (segue.identifier == "segue identifier connecting the 2 views") {
let viewController = segue.destinationViewController as! UINavigationController
let detailview = viewController.topViewController as! nextViewViewController
detailview.element defined in nextview = value to send
}
您可以在网上找到很多使用标识符执行 segue 的示例。这是一个很常见的问题。
我找不到比这更简单的方法了:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController *sourceViewController = self;
UIViewController *destinationController = [mainStoryboard instantiateViewControllerWithIdentifier: @"View3"];
UINavigationController *navigationController = sourceViewController.navigationController;
// Pop to root view controller (not animated) before pushing
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:destinationController animated:YES];