はここで、これはにObjCカテゴリを使用して、一つの代替の実例です:
/* 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
幸い、コンパイラはカテゴリがクラスで実行されるので、定義されたときにすべてのあなたの宣言を定義したことを確認します。プロトコルのような適切なクラス実装で定義されなければならないものがいくつかあります。
これを1トンの小さなファイルに分割すると気をつけます。ビルド時間が実際に苦しんでいる可能性があります。また、このケースでは(あなたのサブクラス化から)、いくらか避けられないが、この点に関するスケーラビリティの問題は、インターフェイス/クラスがあまりにも多くのことを試みていることを通知する役割を果たすため、小さなコンポーネントに分割する必要があります。がんばろう!
iPhone/iPad開発について学ぶ1ヶ月を費やした後、おそらくAppleの開発者が同じコードを書いたコードの大半は、単一のviewcontroller.mファイルを使用しています。プラグマステートメントを追加すると、当面はDarren'sが一番簡単で最善のアプローチに見えます。私はジャスティンのアプローチが好きです。これがより良くなると、私は自分のやり方を実装するかもしれません。あなたの答えはありがとうございました。 – KevinS