2012-08-14 4 views
2

orientationChanged:.h 파일에 신고하지 않고 액세스 할 수있는 이유는 무엇입니까? 애플의 문서에서이 메서드를 찾을 수 없으므로 상속 된 메서드라고 생각하지 않습니다. 당신이 @selector(...)에 전달이 방법을 .h 파일에서 선언해야하는 이유는 무엇입니까?

#import <UIKit/UIKit.h> 

@interface RotationAppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@end 

#import "RotationAppDelegate.h" 

@implementation RotationAppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    UIDevice *device = [UIDevice currentDevice]; 
    [device beginGeneratingDeviceOrientationNotifications]; 
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
    [nc addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:device]; 

    // Override point for customization after application launch. 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

-(void)orientationChanged:(NSNotification *)note { 
    NSLog(@"oriendtationChanged: %i", [[note object] orientation]); 
} 

답변

4

방법은 헤더 파일에 선언 할 필요가 없습니다. 사실, 아무도 런타임에 실행하지 않는 한 그들은 존재할 필요조차 없습니다. orientationChanged: 문자열을 사용하면 @selector(...)이 올바른 선택자를 생성하기에 충분합니다. 런타임에 해당 메서드를 사용할 수있는 한 (즉, 객체의 respondsToSelector:이 해당 객체에 대해 YES을 반환 함) 시스템에서 올바르게 찾아 실행합니다.

관련 문제