2010-07-21 9 views
0

초급 질문입니다. 나는 앱을 만들고 있는데 ViewController에서 선언 한 메소드 (appDelegate (applicationDidBecomeActive에 있음))를 호출하려고합니다. 내가 가진 TestAppDelegate.m에서 그래서 기본적으로AppController에서 AppDelegate에서 선언 한 메서드를 호출하는 방법

, ... FirstViewController.m에서

 
    - (void)applicationDidBecomeActive:(UIApplication 
*)application { 
    // I want to call a method called "dothisthing" that I've defined in 
FirstViewController.m 
    // This does not work: [FirstViewController dothisthing] } 

내가 가지고 ...

 
- (void) dothisthing { 
    NSLog(@"dothisthing"); 
} 

이 내 첫 아이폰 앱, 그래서 어떤 도움이 것 감사하겠습니다. 대신의 첫 번째 인스턴스를 생성하고 ... 인스턴스의 메소드를 호출하거나 (+) 정적으로 메소드를 선언 할 필요가 있으므로

답변

3

방법은 인스턴스 메소드입니다 (-) 무효

FirstViewController* controller = [FirstViewController alloc]; 

[controller dothisthing]; 

[controller release]; 
+0

설명해 주셔서 감사합니다. 어디서 처음으로 인스턴스를 만들어야하는지 정확히 모르겠습니다. AppDelegate.m에서? 완전한 Obj-C 초심자는 여기에서. – buckminsterfuller

+0

글쎄, 그건 컨트롤러의 수명에 달렸습니다 ... 앱의 주/유일한 컨트롤러 인 경우 appDelegate가 컨트롤러를 '소유'(@interface로 선언)하고 applicationDidFinishLoading에서 인스턴스화 한 다음 dealloc에서 해제) – Jaime

+0

고마워! 내가 일을 일해야하지만 하나 개 더 질문은 ... 내가 경고 얻을 : FirstViewController가 '-dothisthing' 여기에 응답하지 않을 수 있습니다를 코드입니다 : FirstViewController * 컨트롤러 = [FirstViewController의 ALLOC] \t [컨트롤러 dothisthing]; // this는 경고를 던집니다 – buckminsterfuller

0

사용이 간단한 NSNotificationCenterexample의 코드 조각을 게시 한 비슷한 질문이 있습니다. 매력을 발휘합니다!

관련 문제