2011-11-02 3 views
1

MKMapView에서 터치 이벤트를 감지하기 위해 사용자 정의 제스처 인식기 (Intercepting/Hijacking iPhone Touch Events for MKMapView 링크에 명시된대로)를 사용하고 있습니다. 제스처 인식기는 WildcardGestureRecognizer.h에 정의되어 있으며 WildcardGestureRecognizer.m 파일에 구현되어 있습니다. 이 제스처 인식기가 MKMapview에 추가되면, 하나는 내가 (MKMapView 함유) MainViewController에서 방법 tapMethod을 호출 할이 터치 감지를 기반으로 모든 터치 이벤트사용자 정의 클래스 파일에서 MainViewController의 메서드 호출

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


} 

다음의 방법에서 읽을 수 있습니다.

-(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]; 

    } 

다음과 같은 노력이 인쇄 "탭지도"를 수행하지만 변수 dontUpdateLocation의 값을 변경하지 않습니다. 어떻게해야합니까? 나는 당신의 의견에서 이해하는 것과

+0

어떤 값으로 'dontUpdateLocation' 변수가 초기화 되었습니까? 'tapMethod'를 제외하고이 변수를 수정하는 다른 메소드는 무엇입니까? – Mat

+0

@Mat이 값은 0으로 초기화됩니다.이 변수를 수정하는 다른 메소드는 없습니다. – chatur

+0

'NSLog (@ "% i", dontUpdateLocation),''NSLog (@ "맵핑 된 맵"),'? dontUpdateLocation은 int입니까? – Mat

답변

1

, 나는 문제가 때문입니다 생각 당신이 할 때 :

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

기존 mainviewcontroller에 대한 참조를 생성하지 않는, 그러나 당신이 만드는 메모리 내의 다른 오브젝트를 가리키는 다른 포인터. 당신은 저장하는 AppDelegate에를 사용 (설정 @property를하고 @synthesize) 변수를 다음과 같이 액세스 할 수 있습니다 : 당신이 이러한 패턴의 모양과 깊이 보시기 바랍니다

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

: Singletons, MVC, 그리고 Delegation

희망이 도움이됩니다.

+0

인내심을 가져 주셔서 감사합니다. 변수를 저장하기 위해 appDelegate 메소드를 사용했으며, 필요에 따라 작동합니다. – chatur

관련 문제