问题
In my app there are two view controllers. I wrote touchesmoved method in both the view controllers. But even if i touch on second view controller on simulator, the first VC touches moved method is called.
// for VCOne
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"first view vc move method");
UIStoryboard *storyboard = self.storyboard;
ThreadedView *secViewController = [storyboard instantiateViewControllerWithIdentifier:@"threaded"];
[self.view addSubview:secViewController.view];
[self viewDidUnload];
}
So once the above method is called, it will navigate to second view controllers "ViewDIDLoad" method. In this file, i have written one more touches moved method.
// for VCTwo
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"second view vc move method");
}
Now if i touch in second view controller, the first VC touchesmethod is called instead of second VC touches method.
Is there any way to do this? I needed different touches moved method for different view controllers.
回答1:
If you want to transit from first view controller to second view controller,
you can try this method: presentModalViewController:animated:
.
In your touchesMoved:withEvevt:
of first view controller
NSLog(@"first view vc move method");
UIStoryboard *storyboard = self.storyboard;
ThreadedView *secViewController = [storyboard instantiateViewControllerWithIdentifier:@"Threaded"];
[self presentModalViewController:secViewController animated:NO];
In second view controller, you can use dismissModalViewControllerAnimated:
to go back to first view controller.
Hope this will help.
来源:https://stackoverflow.com/questions/12741923/touchesmoved-method-for-two-view-controllers