objCのデザインパターンについての初心者の質問。 私は他のアプリでも使う予定の私のiPhoneアプリの機能を書いています。この機能は、Viewcontroller1とViewcontroller2の2つのクラスにわたって書かれています。 Viewcontroller1はナビゲーションコントローラのルートビューであり、Viewcontroller2を押すことができます。アプリの残りの部分はViewController1のみを使用し、ViewController2には直接アクセスしません。ただし、ユーザーイベントによって がトリガーされた場合、ViewController2は restアプリにメッセージを送信する必要があります。 私の質問は、それを達成する最良の方法は何ですか?2つのビューコントローラとデリゲートでの再利用
現在、Viewcontroller2からメッセージを送信するために2レベルの委任を使用しています。最初にViewcontroller1に送信し、ViewController1にのの残りの部分またはアプリケーションの代理人に送信させます。だから私のコードは次のようになります:
//Viewcontroller1.h
@protocol bellDelegate
-(int)bellRang:(int)size;
@end
@interface Viewcontroller1 : UITableViewController <dummydelegate> {
id <bellDelegate> delegate;
@end
//Viewcontroller1.m
@implementation Viewcontroller1
-(void)viewDidLoad {
//some stuff here
Viewcontroller2 *vc2 = [[Viewcontroller2 alloc] init];
vc2.delegate = self;
[self.navigationController pushViewController:vc2
animated:YES];
}
-(int)dummyBell:(int)size {
return([self.delegate bellRang:size]);
}
//Viewcontroller2.h
@protocol dummyDelegate
-(int)dummyBell:(int)size;
@end
@interface Viewcontroller2 : UITableViewController {
id <dummyDelegate> delegate;
@end
//Viewcontroller2.m
@implementation Viewcontroller2
-(int)eventFoo:(int)size {
rval = [self.delegate dummyBell:size];
}
@end
ご確認いただきありがとうございます。現在、私のコードは、そのような用語が存在するかどうかわからない、デリゲート階層を越えてジャンプすることができないので混乱しています。 – netcharmer