How to come parent viewcontroller from child viewcontroller by using scrolling action?

247 views Asked by At

I have two UIViewController named as ViewControllerA and ViewControllerB. ViewControllerA is the parent class and ViewControllerB is a child class, it is view by [self.navigationController pushViewController:viewControllerB animated:YES]; from ViewControllerA class. In ViewControllerB class i hidden the NavigationBar. In button action i coded to come ViewControllerA from ViewControllerB [self.navigationController popViewControllerAnimated:YES];. Now, i want to come ViewControllerA from ViewControllerB using swapping action(Scroll to previous screen) rather than using UIButton. How can i do this? Can anyone please provide me any suggestion or ideas? Thanks in advance.

2

There are 2 answers

0
Mehul Mistri On BEST ANSWER

Use this in child controller

- (void)viewDidLoad 
{    
    UISwipeGestureRecognizer  *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)];
    [[self view] addGestureRecognizer:recognizer];
    [recognizer release]; 
    [super viewDidLoad];
}

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
 {
    [self.navigationController popViewControllerAnimated:YES];
    NSLog(@"Swipe received.");
 }

Use Direction as you want..

Happy Coding...

0
Kyr Dunenkoff On

You can try to use UISwipeGestureRecognizer on your child view with handler method that does the [self.navigationController popViewControllerAnimated:YES];.