Interface Builderを使用してUIViewといくつかのサブビュー(UIWebView、UIToolbar、いくつかのUIBarButtonItems、進行状況インジケーターなど)を設計したいのですが、UIViewControllerを使用して、従来はこれを行う必要はないと思います。presentViewController:animated
等
そこで、 .h
次のようなファイルコードを使用してカスタムクラスを作成しました。
@interface FileInteractionManager : NSObject {
}
@property (nonatomic, retain) IBOutlet UIView *fileView;
@property (nonatomic, retain) IBOutlet UIWebView *fileWebView;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *printButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *optionsButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *doneButton;
私の.mファイルは次のとおりです。
@implementation FileInteractionManager
@synthesize fileView, fileWebView, doneButton, optionsButton, printButton;
-(id)init {
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FileInteractionView" owner:self options:nil];
NSLog(@"Load success!");
return self;
}
最後に、「FileInteractionView.xib」という名前のスタンドアロンxibファイルを作成し、ファイルの所有者を上記で作成したカスタムクラスに変更して、IBOutletsを接続します。
クラスでメソッドを呼び出すとinit
、デバッガーですべてのIBOutletオブジェクトが正しくインスタンス化されていることがわかります。
私の質問は次のとおりです。
この方法は
loadNibNamed:owner:options:
、スタンドアロンの.xibファイルをロードする正しい方法ですか?このメソッドが私が使用しない配列を返すという事実は好きではありません(返されたトップレベルのオブジェクトは私の変数fileView
と一致しますが、私はすでにInterface Builderを介してそれらをリンクしています)。私の一般的なアプローチは私の問題を解決するのに正しいですか?
UIView
まったく新しいUIViewControllerを表示して閉じるのではなく、既存のUIViewControllerに追加できる単純なオブジェクトが必要だったため、上記の手順を実行しました。