TouchesMoved method for two view controllers

丶灬走出姿态 提交于 2019-12-24 20:23:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!