1

I am using a custom gesture recognizer (as given in the link Intercepting/Hijacking iPhone Touch Events for MKMapView) for detecting touch events on MKMapView. gesture recognizer is defined in WildcardGestureRecognizer.h and implemented in WildcardGestureRecognizer.m file. When this gesture recognizer is added to MKMapview, one can read from following method any touch events

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (touchesBeganCallback)
        touchesBeganCallback(touches, event);
    NSLog(@"touchesBegan");


}

Based on this touch detection I want to call method tapMethod from MainViewController(Containing MKMapView).

-(void) tapMethod
{
    dontUpdateLocation =1;// a variable to check stoppoing of location update.
    NSLog(@" map tapped");
}

I tried following

  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        if (touchesBeganCallback)
            touchesBeganCallback(touches, event);
        NSLog(@"touchesBegan");
        MainViewController *updateController = [[MainViewController alloc]init ];
        [updateController tapMethod];
        [updateController release];

    }

It does print "map tapped" but doesn't change value of variable dontUpdateLocation. How can I do it?

Community
  • 1
  • 1
chatur
  • 2,365
  • 4
  • 24
  • 38
  • With what value the variable `dontUpdateLocation` is initialized? What other method modifies this variable, apart `tapMethod`? – Mat Nov 02 '11 at 10:12
  • @Mat it is initialized with value 0. No other method modifies this variable. – chatur Nov 02 '11 at 10:15
  • What about `NSLog(@"%i",dontUpdateLocation);` before `NSLog(@" map tapped");`?..dontUpdateLocation is an int? – Mat Nov 02 '11 at 10:18
  • yes. it is int. I tried that and it prints "1","map tapped" . However in method - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated, when i print NSLog(@"will change map with %d", dontUpdateLocation); I always get 0. – chatur Nov 02 '11 at 10:23
  • So what's the problem? the value changes after running the method. why do you say that does not change? – Mat Nov 02 '11 at 10:27
  • @Mat, last comment was incomplete, please see updated comment. Probably value dontUpdateLocation in MainViewController is not changed it is only changed in updateController defined temporarily. – chatur Nov 02 '11 at 10:43

1 Answers1

1

From what I understand from your comments, I think the problem is due to the fact that when you do this:

MainViewController *updateController = [[MainViewController alloc]init ];
[updateController tapMethod];
[updateController release];

you're not creating a reference to the existing mainviewcontroller, but you are creating a different pointer that points to another object in memory. You may use the appDelegate to store(set @property, and @synthesize) the variable and then access like this:

YourAppDelegate *appDel=(YourAppDelegate *)[[UIApplication sharedApplication] delegate];
appDel.dontUpdateLocation=1;

I suggest you take a look and depth of these patterns: Singletons, MVC, and Delegation

Hope this helps.

Mat
  • 7,613
  • 4
  • 40
  • 56
  • Thanks a lot Mat for your patience. I used appDelegate method to store the variable and it works just as required. – chatur Nov 02 '11 at 11:09