당신이 당신의 기본 클래스를 액세스, 하나는 현재의 클래스는 설명했습니다 무엇을 할
에서 상속, 당신은 이후 다소 복잡 부모 뷰의 속성에 액세스 할 필요가 이것은 두 클래스가 서로를 참조하려고 할 때 거의 끝날 것입니다. 따라서 당신이 가장 가능성이처럼 다소 찾고, 위임 패턴을 만들어야합니다이
ParentView.h ChildView.h에의
@protocol IAmYourFatherAndMotherProtocol
@class ChildView;
@interface ParentView : UIViewController <IAmYourFatherAndMotherProtocol>
{
NSInteger statusID;
}
@property (nonatomic) NSInteger statusID;
@protocol IAmYourFatherAndMotherProtocol
@property (nonatomic) NSInteger statusID;
@end
@end
#import "ParentView.h"
@interface ChildView : UIViewController
{
id<IAmYourFatherAndMotherProtocol> delegate;
}
@property (nonatomic, assign) id <IAmYourFatherAndMotherProtocol> delegate;
ParentView.m에 ChildView를 만드는 위임자로 '자아'를 설정해야합니다 (예 :
ChildView *newChild = [[ChildView alloc] init];
newChild.delegate = self;
그렇게함으로써, 당신은이 같은 ChildView.m에 ParentView의 "statusID"를 액세스 할 수 있습니다
delegate.statusID = 1337;
희망이
당신이에 코드 예제가 있습니까 도움 :로부터 부모에 대한 참조를 유지 자식보기 컨트롤러 및 부모 setStatusId : 메서드를 호출 할? 또한, 어느 쪽의 메소드가 부모의 delegate 패턴 또는 setStatusId 메소드를보다 세련되게 할까? –