Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

In the child subview, I trying calling [super statusid:updatedValue]; to update statusid to a new value, but this creates an error. How can i update statusid in the parent? Anyone know how to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
474 views
Welcome To Ask or Share your Answers For Others

1 Answer

with "super" you access your base class, the one your current class has inherited from

to do what you've explained, you need to access a property of your parent view, which is rather complicated since this will most likely end with both classes trying to reference each other. thus you will most likely have to create a delegate pattern, looking somewhat like this

ParentView.h

@protocol IAmYourFatherAndMotherProtocol

@class ChildView;

@interface ParentView : UIViewController <IAmYourFatherAndMotherProtocol>
{
NSInteger statusID;
}

@property (nonatomic) NSInteger statusID;

@protocol IAmYourFatherAndMotherProtocol
@property (nonatomic) NSInteger statusID;
@end

@end

in ChildView.h

#import "ParentView.h"

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

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

when creating your ChildView in ParentView.m, you have to set "self" as delegate, eg:

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

by doing so, you can access "statusID" of your ParentView in ChildView.m like this:

delegate.statusID = 1337;

hope this helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...