Setting property value of parent class viewcontroller from child viewcontroller?

Does anyone know how to update a property value from a subview (child) view controller? I have an int property called statusid defined using gettor / settor in the parent view controller. [self.view addSubview: detailsVC.view];

In the child sub, I try to call [super status: updateValue]; to update statusid to a new value, but this creates an error. How can I update statusid in parent? Does anyone know how to do this?

+3
source share
2 answers

"" ,

, , , , , , , . , , , , .

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.h

#import "ParentView.h"

@interface ChildView : UIViewController
{
  id<IAmYourFatherAndMotherProtocol> delegate;
}

@property (nonatomic, assign) id <IAmYourFatherAndMotherProtocol> delegate;

ChildView ParentView.m "self" , :

ChildView *newChild = [[ChildView alloc] init];
newChild.delegate = self;

"statusID" ParentView ChildView.m :

delegate.statusID = 1337;

,

+6

- , /-.

, setStatusId: , , (, ) .

0

Source: https://habr.com/ru/post/1716706/


All Articles