、あなたは親ビューのプロパティにアクセスする必要があり、これは、両方のクラスがお互いを参照しようとしている可能性が高いでしょう。 ので、あなたが最も可能性の高いややChildView.h
#import "ParentView.h"
@interface ChildView : UIViewController
{
id<IAmYourFatherAndMotherProtocol> delegate;
}
@property (nonatomic, assign) id <IAmYourFatherAndMotherProtocol> delegate;
ParentView.mであなたのChildViewを作成するには、この
ParentView.h
@protocol IAmYourFatherAndMotherProtocol
@class ChildView;
@interface ParentView : UIViewController <IAmYourFatherAndMotherProtocol>
{
NSInteger statusID;
}
@property (nonatomic) NSInteger statusID;
@protocol IAmYourFatherAndMotherProtocol
@property (nonatomic) NSInteger statusID;
@end
@end
のように見える、デリゲートパターンを作成する必要があります代理人として「自己」を設定する必要があります。例:
ChildView *newChild = [[ChildView alloc] init];
newChild.delegate = self;
そうすることによって、あなたはこのようChildView.mであなたのParentViewの「statusID」にアクセスすることができます
delegate.statusID = 1337;
希望これは
を助け、あなたがするコード例を持っていますか:から親への参照を保持子ビューコントローラを呼び出し、親のsetStatusId:メソッドを呼び出しますか?また、どのメソッドが親クラスのデリゲートパターンやsetStatusIdメソッドをよりエレガントにしていますか? –