모 놀리 식 파일을 만드는 것처럼 보일 수도 있지만 ViewController는 실제로이 모든 것들을위한 장소입니다. 만약 당신이 제안한 것을한다면 (그것은 전적으로 가능합니다), 당신은 거의하지 않는 파일들로 끝날 것입니다.
한 가지 방법이 큰 파일 구성을 계속하는 것은과 같이 프라그 마크와 방법의 별도의 그룹입니다 :
#pragma mark lifecycle methods
-(void)dealloc{}
-(id)init{}
-(id)initWithCoder:
#pragma mark target-action
-(id)doSomethingAction:(id)sender{}
-(id)doSometingElse:(id)sender{}
엑스 코드는 프라 그마 마크 및 그룹에게 풀다운 항목 표시 줄에 당신을위한 방법을 분석한다 쉬운 접근을 위해. 이 목록의 메소드도 알파벳 순서로 나열됩니다.
/* File: Header A */
@interface MONViewController : NSViewController
{
unsigned anIvar;
}
@property (nonatomic, readonly) unsigned anIvar;
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle;
- (void)dealloc;
- (void)viewDidLoad;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
/* (continued) */
@end
/* File: Header A or Header B, depending on how you want to organize it */
@interface MONViewController (EventCallbacks)
- (IBAction)triviaButtonWasPressed:(id)sender;
/* (continued) */
@end
/* File: Imp A */
@implementation MONViewController
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle { /* ... */ }
- (void)dealloc { /* ... */ }
- (unsigned)anIvar { /* ... */ }
- (void)viewDidLoad { /* ... */ }
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { /* ... */ }
/* (continued) */
@end
/* File: Imp A or Imp B, depending on how you want to organize it */
@implementation MONViewController (EventCallbacks)
- (IBAction)triviaButtonWasPressed:(id)sender { /* ... */ }
/* (continued) */
@end
다행히, 컴파일러는 범주를 정의 할 때 클래스에서 수행되는 것처럼, 모든 선언을 정의한 있는지 확인합니다 :
iPhone/iPad 개발에 대해 한 달을 보냈다면, 필자가 본 대부분의 코드와 Apple 개발자 코드가 같은 viewcontroller.m 파일을 사용합니다.pragma 문을 추가하면 당분간 Darren 's가 가장 간단하고 최상의 방법 인 것처럼 보입니다. 나는 저스틴의 접근 방식을 좋아하지 만, 이럴 때 더 잘된다면, 나는 일하는 방식을 구현할 수 있습니다. 답장을 보내 주셔서 감사합니다. – KevinS