Question

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.

Was it helpful?

Solution

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...

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top