3

i am aware that uiview does not have navigational control. Thus, i am not able to push from the uiview to the next uiviewcontroller.

here is the code of my method. Please help. Thanks!

 - (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {
    CGPoint pointInView = [recognizer locationInView:self];
    NSLog(@"%f , %f",pointInView.x,pointInView.y);

    if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (193)  && pointInView.y <=(218)) )
    {

        // how to push to next viewcontroller here?

        UIView *view = [UIGestureRecognizer view]; //what should i do for this code?


        [self viewController];
    }
}

-(TestViewViewController*)viewController
{
    for (UIView *next = [self superview]; next; next = next.superview)
    {
        UIResponder *nextResponder = [next nextResponder];

        if([nextResponder isKindOfClass:[TestViewViewController class]])
        {

            return (TestViewViewController*)nextResponder;
        }
    }

    return nil;
}
Akbari Dipali
  • 2,173
  • 1
  • 20
  • 26
benedict
  • 59
  • 10

1 Answers1

0

If you want to get viewcontroller having a view than you can use nextResponder method

So first you get the view from gestureRecognizer:

UIView *view = [gestureRecognizer view];

and than search for the viewcontroller containing the view

Look here

Edit:

 if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (193)  && pointInView.y <=(218)) )
    {

        // how to push to next viewcontroller here?

        UIView *view = [recognizer view]; //what should i do for this code?

       UIViewController *viewController = [self getViewControllerFromView:view];

       if(viewController) {
          // do whatever you want...
         UIViewController *newViewController = ...
         [viewController.navigationController pushViewController:newViewController animated:YES];
       }

    }

... I rewrote method get ViewController to your case. To get it from some view:

-(UIViewController*)getViewControllerFromView:(UIView*) view
{
    if([[view nextResponder] isKindOfClass:[UIViewController class]])
    {
        return (UIViewController*)[view nextResponder];
    }
    else {

        for (UIView *next = [view superview]; next; next = next.superview)
        {
            UIResponder *nextResponder = [next nextResponder];

            if([nextResponder isKindOfClass:[UIViewController class]])
            {
                return (UIViewController*)nextResponder;
            }
        }
    }

    return nil;
}

new edit::

your EAGLView has @property (nonatomic, retain) UIViewController *viewController; ADD @synthesize viewController = _viewController; to .m file.

CoreMotionAppDelegate::

MainViewController * itemsViewController = [[MainViewController alloc]init];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
    glView.viewController = itemsViewController;  


    [glView startAnimation];
    [[self window]setRootViewController:navController];

And than in your scrollViewDoubleTapped method just

EAGLView *v = (EAGLView*)[recognizer view];  
UIViewController *viewController =  v.viewController;
Community
  • 1
  • 1
B.S.
  • 21,660
  • 14
  • 87
  • 109
  • hi george, i edited the codes as you suggested but i'm not sure how to link the uiview to the responder. i edited the codes above. please take a look. Thanks! – benedict Mar 21 '13 at 08:11
  • I see that you do not understand what you are doing at all. Wait i will edit the answer – B.S. Mar 21 '13 at 09:11
  • Hi george. i added your codes in to my project and added this two lines of codes at the // do whatever you want area. TestViewViewController *newViewController = [[ TestViewViewController alloc]initWithNibName:nil bundle:nil]; [viewController.navigationController pushViewController:newViewController animated:YES]; } but i ran into some error : 'NSInvalidArgumentException', reason: '+[UIGestureRecognizer view]: unrecognized selector sent to class 0x3f342908' please help. Thanks George! – benedict Mar 21 '13 at 09:58
  • my fault, because of writing a code in browser, replace [UIGestureRecognizer view]; to [recognizer view]; – B.S. Mar 21 '13 at 10:00
  • Hi George, I have added the above code, however I am still unable to push to a new UIViewController. My view = EAGL View contains a 3D model, when user touch a certain part of the model, it will link to the new UIViewController, is it possible to do this? – benedict Mar 22 '13 at 00:56
  • add log to if(viewController) {.. here } and say if it finds the viewcontroller – B.S. Mar 22 '13 at 04:11
  • Hi George, I added a NSLog above the if(viewController) however, the program never read the NSLog. when i debug, i notice that my UIView *next at the for (UIView *next = [view superview]; next; next = next.superview) have an absurb value, it says (info = 1, value = 3574903). Is this the source of the problem? Please help, Thanks. – benedict Mar 22 '13 at 05:58
  • Do not know how to help. Share than a code, how you add the view and gesture recoginzer – B.S. Mar 22 '13 at 06:04
  • Hey George, I have upload my codes in media fire, here is the link http://www.mediafire.com/?6d1v2rtva2n1uxe The codes that you have suggested is located in EAGL view.m. Please help. Thanks – benedict Mar 22 '13 at 06:16
  • Hi George,I accidentally deleted the file, here is the new link http://www.mediafire.com/?14cefzmi7f671vr. Thanks – benedict Mar 22 '13 at 06:28
  • I will look i half an hour – B.S. Mar 22 '13 at 06:33
  • I edited how to get view controller, it gets it, but doesn't push – B.S. Mar 22 '13 at 07:22
  • Hi George, for the scrollviewDoubleTap method, the EAGLView *v = (EAGLView*)[recognizer view]; UIViewController *viewController = v.viewController; is this placed in the if ((pointInView.x >= (231.0) && pointInView.y >= (162)) ) Or we can just ignore it? and just place the code as you suggested above. – benedict Mar 22 '13 at 07:51