【发布时间】:2011-11-02 09:40:06
【问题描述】:
我正在使用自定义手势识别器(在链接Intercepting/Hijacking iPhone Touch Events for MKMapView 中给出)来检测 MKMapView 上的触摸事件。手势识别器在 WildcardGestureRecognizer.h 中定义并在 WildcardGestureRecognizer.m 文件中实现。当将此手势识别器添加到 MKMapview 时,可以从以下方法中读取任何触摸事件
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (touchesBeganCallback)
touchesBeganCallback(touches, event);
NSLog(@"touchesBegan");
}
基于此触摸检测,我想从 MainViewController(Containing MKMapView) 调用方法 tapMethod。
-(void) tapMethod
{
dontUpdateLocation =1;// a variable to check stoppoing of location update.
NSLog(@" map tapped");
}
我试过了
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (touchesBeganCallback)
touchesBeganCallback(touches, event);
NSLog(@"touchesBegan");
MainViewController *updateController = [[MainViewController alloc]init ];
[updateController tapMethod];
[updateController release];
}
它会打印“map tapped”,但不会更改变量 dontUpdateLocation 的值。 我该怎么做?
【问题讨论】:
-
用什么值初始化变量
dontUpdateLocation?除了tapMethod,还有什么其他方法可以修改这个变量? -
@Mat 它被初始化为 0。没有其他方法修改这个变量。
-
NSLog(@"%i",dontUpdateLocation);在NSLog(@" map tapped");之前呢?..dontUpdateLocation 是一个整数? -
是的。它是 int。我试过了,它打印出 "1","map tapped" 。但是在方法 - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated 中,当我打印 NSLog(@"will change map with %d", dontUpdateLocation);我总是得到 0。
-
那么问题出在哪里?运行该方法后值会发生变化。为什么说不变?