Navigate Back to previous view controller

2019-02-01 10:26发布

I have a UIView->UICollectionView->UICollectionViewCell. I am trying to navigate back programatically but none of these works. The code did called. I am using StoryBoard.

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

9条回答
小情绪 Triste *
2楼-- · 2019-02-01 11:19

You need to use:

[self.navigationController popToRootViewControllerAnimated:YES];

This will bring you back to the root view controller.

If you want to navigate back to previous view controller, you should implement:

[self.navigationController popViewControllerAnimated:YES];
查看更多
我想做一个坏孩纸
3楼-- · 2019-02-01 11:21

Try it....

#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];
}
查看更多
够拽才男人
4楼-- · 2019-02-01 11:22
- (void) goBack:(NSNotification *) notification 
{ 
   if(!self.YOrView.isHidden)
      self.YOrView.hidden = YES;
}
查看更多
登录 后发表回答