2013-10-03 2 views
0

사진을 Facebook 앱에 업로드하려고하는데 View Controller에 대한 .h 파일에 두 개의 @interfaces가 필요하다고 생각합니다.동일한 .h 파일에 두 개의 @interfaces가있는 경우

다음은 내 ViewController.h 파일입니다.

#import <UIKit/UIKit.h> 
#import <Social/Social.h> 
@interface FirstViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> { 
UIImagePickerController *bailey; 
UIImagePickerController *baileys; 
UIImage *image; 
IBOutlet UIImageView *imageView; 
} 
- (IBAction)TakePhoto; 
- (IBAction)ChooseExisting; 
@end 
@interface FirstViewController : UIViewController { SLComposeViewController  *slComposeViewController; 
UIImage *image; } 
- (IBAction)ShareFB; 
@end 

내 아이폰에이 코드를 빌드하려고 또는 에뮬레이터가 도움에 미리

/Users/Condrum/Desktop/project/myApp/myApp/FirstViewController.h:21:1: Duplicate interface definition for class 'FirstViewController' 

감사를 말할 때.

-Condrum.

+0

같은 이름의 인터페이스가 두 개있는 이유는 무엇입니까? 두 가지 다른 이름을 사용하거나 모든 것을 하나의 정의에 넣으십시오. – Thilo

+0

나는 코코아 [방법 명명 규칙] (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html#//apple_ref/doc)을 채택하는 것이 좋습니다./uid/20001282-BCIGIJJF), 예를 들어 'TakePhoto','ChooseExisting','ShareFB'보다는'takePhoto','chooseExisting','shareFB'를 사용합니다. – Rob

+0

메서드 명명 규칙에 대한 조언을 주셔서 감사합니다. – Condrum

답변

1

패턴이 .H 파일로 단일 공중 인터페이스를 넣어이다

@interface FirstViewController : UIViewController 

// in here put those public properties and method declarations that 
// other classes need to have access to 

@end 

나서 private class extension으로하는 .m 파일에서 상기 제 @implementation 입력 :

@interface FirstViewController() <UIImagePickerControllerDelegate, UINavigationControllerDelegate> 

// in here, place those private properties and instance variables that 
// only this class needs to be aware of 

@end 

참고 이렇게 두 번째 인터페이스는 () 구문을 사용합니다.이 구문은 인터페이스가 이전에 정의 된 인터페이스를 확장하고 있음을 나타냅니다.

그러나 두 인터페이스를 동일한 .h 파일에 넣을 필요는 없습니다 (왜 두 개의 인터페이스가 있으며 하나의 인터페이스로 결합하는 것이 더 합리적 일 수 있습니다). private 클래스 확장의 주된 가치는 구현에만 관심이있는 세부 사항으로 인터페이스를 확장 할 수 있고 멋진 단순한 공용 인터페이스가 어수선하게 흩어지는 것을 피할 수 있다는 것입니다. 따라서 일반적으로 .h 파일에 공용 인터페이스를 유지하고 개인 파일을 .m 파일의 클래스 확장으로 이동하십시오.

자세한 내용은 Class Extensions Extend the Internal Implementation을 참조하십시오.

+0

감사합니다. Rob! 그것은 훌륭하게 작동했으며 지금은 계속할 수 있지만 나중에 세 번째 @interface를 구현해야 할 수도 있습니다. 어떻게해야합니까? – Condrum

+0

@Condrum 또 다른 확장. 또는 [카테고리] (https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html#//apple_ref/doc/uid/TP40011210-CH6-SW2). 당신이 또 다른'@ 인터페이스 '를 필요로하는 경우는 드뭅니다. (왜 당신이 3 번째 인터페이스가 필요하다고 생각하는지에 매료되었지만) 할 수 있습니다. – Rob

+0

페이스 북에 업로드하는 데 사진을 두 번째 찍고 트위터에 업로드하기 위해 사진을 찍는 것이 필요했기 때문에 세 번째 @interface가 필요합니다. 계속 통합하기 전에 페이스 북을 설치할 때까지 기다릴 수 있습니다. 지저귀다. – Condrum