导航回到以前的视图控制器(Navigate Back to previous view contro

2019-08-31 11:07发布

我有一个UIView->UICollectionView->UICollectionViewCell 。 我想以编程方式导航回但这些作品。 该代码没有调用。 我使用的故事板。

- (void) goBack:(NSNotification *) notification {
      // [self.navigationController popViewControllerAnimated:YES];
     //  [self dismissViewControllerAnimated:YES completion:nil];
      [self.navigationController popToRootViewControllerAnimated:YES];
}

Answer 1:

您需要使用:

[self.navigationController popToRootViewControllerAnimated:YES];

这将带你回到根视图控制器。

如果你想返回到相应的视图控制器,你应该实现:

[self.navigationController popViewControllerAnimated:YES];


Answer 2:

通过使用下面的行,我们可以去父视图控制器

[self.navigationController popViewControllerAnimated:YES]; 

通过使用下面行中,我们可以移动到主/根视图控制器

[self.navigationController popToRootViewControllerAnimated:YES]; 

通过使用下面的线,我们可以移动到任何视图控制器

[self.navigationController popToViewController:viewControllerObject animated:YES]; 


Answer 3:

怎么样...

 [self.navigationController dismissViewControllerAnimated:YES completion:NULL];

假设您目前在一个基于导航控制器,你想回到以前的控制器,你钻进了一个基于导航控制器之前。



Answer 4:

为便于复制粘贴斯威夫特的解决方案:

navigationController?.popViewControllerAnimated(true)


Answer 5:

试试吧....

#import "bookdescriViewController.h" // import here your class name 

- (IBAction)backButton:(id)sender 
{
  bookdescriViewController *previosVC = [[bookdescriViewController alloc]init];
  [self.navigationController popViewControllerAnimated:YES]; // go to previous view controller
  [self.navigationController popToRootViewControllerAnimated:YES]; // go to root view controller
  [self.navigationController popToViewController:previosVC animated:YES]; // go to any view controller
  [previosVC release];
}


Answer 6:

雨燕4.1:

navigationController.popViewController(animated: true)


Answer 7:

随着swift3,

@IBAction func back(_ sender: UIButton) {
    self.dismiss(animated: true, completion: nil)     
}


Answer 8:

- (void) goBack:(NSNotification *) notification 
{ 
   if(!self.YOrView.isHidden)
      self.YOrView.hidden = YES;
}


Answer 9:

回到父视图控制器和dealloc的当前视图控制器,例如:

- (void)applicationDidEnterBackground:(NSNotification *)notification
{
    NSInteger numberOfViewControllers = self.navigationController.viewControllers.count;

    UIViewController *vc = [self.navigationController.viewControllers objectAtIndex:numberOfViewControllers - 2];

    [self.navigationController popToViewController:vc animated:NO];
}

或另一视图控制器



文章来源: Navigate Back to previous view controller