Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 是否从子viewcontroller设置父viewcontroller类的属性值?_Objective C_Iphone_Uiviewcontroller_Scope - Fatal编程技术网

Objective c 是否从子viewcontroller设置父viewcontroller类的属性值?

Objective c 是否从子viewcontroller设置父viewcontroller类的属性值?,objective-c,iphone,uiviewcontroller,scope,Objective C,Iphone,Uiviewcontroller,Scope,有人知道如何从子视图(子)视图控制器更新属性值吗? 我在父视图控制器中使用gettor/settor定义了一个名为statusid的int属性。 [self.view addSubview:detailsVC.view] 在子视图中,我尝试调用[super statusid:updatedValue];将statusid更新为新值,但这会产生错误。如何更新父级中的statusid?有人知道怎么做吗?在super上调用方法会调用超类的方法实现,它会调用superview的/super view控制

有人知道如何从子视图(子)视图控制器更新属性值吗? 我在父视图控制器中使用gettor/settor定义了一个名为statusid的int属性。 [self.view addSubview:detailsVC.view]


在子视图中,我尝试调用[super statusid:updatedValue];将statusid更新为新值,但这会产生错误。如何更新父级中的statusid?有人知道怎么做吗?

在super上调用方法会调用超类的方法实现,它会调用superview的/super view控制器的实现

您需要从子视图控制器保留对父视图的引用,并调用父视图上的setStatusId:方法,或者在两者之间创建一个委托模式,以使子视图的委托(可能设置为父视图)知道状态ID已更改。

使用“super”访问基类,当前类继承自的类

要按照您所解释的操作,您需要访问父视图的属性,这相当复杂,因为这很可能会导致两个类都试图相互引用。 因此,您很可能必须创建一个委托模式,看起来有点像这样

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中访问ParentView的“statusID”。m如下所示:

delegate.statusID = 1337;

希望这对您有所帮助

您是否有代码示例:从子视图控制器保留对父视图的引用,并在父视图控制器上调用setStatusId:方法?另外,哪种方法比委托模式或父对象上的setStatusId方法更优雅?只是澄清一下。我要做的是更改MKAnnotation视图中的属性,该视图包含一个AnnotationView,该视图具有UIViewController的详图索引。我想从详图索引的viewcontroller更改MKAnnotation的属性值。那么您有一个包含(其他?)注释视图的MKAnnotationView?不管怎么说,我很确定你还是要用和我贴的类似的方式来做。有没有办法把它扩展成一种方法?换句话说,调用类似于[delegate doSomething:YES];???您需要在协议中声明该特定方法,在本例中是IAmYourFatherAndMotherProtocol(应该选择一个较短的名称…),并在委托(ParentView)中实现它,就像这里所示的NSInteger
ChildView *newChild = [[ChildView alloc] init];
newChild.delegate = self;
delegate.statusID = 1337;