2012-06-27 3 views
1

다음 메서드는 viewController에 있습니다.다른 개체를 가리키는 메서드 선택기

refreshTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshLabels) userInfo:nil repeats:YES]; 

appDelegate (또는 다른 클래스) 내부의 메서드를 현재 개체 대신 선택기에서 선택할 수 있습니까?

AppDelegate *ad = (AppDelegate *) [[UIApplication sharedApplication] delegate]; 
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector([ad refreshLabels]) userInfo:nil repeats:YES]; 

감사 : 같은

!

답변

1

시도해보십시오. 대상에 대한 인수로 '자동'으로 설정하여 문제의 코드,하지만 당신은 전화하려고하는 방법에

target 
The object to which to send the message specified by aSelector when the timer fires. The target object is retained by the timer and released when the timer is invalidated. 

aSelector 
The message to send to target when the timer fires. The selector must correspond to a method that returns void and takes a single argument. The timer passes itself as the argument to this method. 

선언 refreshLabels 방법이 있어야한다 AppDelegate에의

AppDelegate *ad = (AppDelegate *) [[UIApplication sharedApplication] delegate]; 
refreshTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:ad selector:@selector(refreshLabels) userInfo:nil repeats:YES]; 

, AppDelegate

+0

나는 이것을 이해할 수 없다고 생각할 수 없다 ... 고맙다! – Linus

+0

당신은 .. 오신 것을 환영합니다 .. :) – janusbalatbat

관련 문제