Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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
如何在iPhone中从子视图更新superview UILabel文本?_Iphone_Ios_Objective C_Uilabel - Fatal编程技术网

如何在iPhone中从子视图更新superview UILabel文本?

如何在iPhone中从子视图更新superview UILabel文本?,iphone,ios,objective-c,uilabel,Iphone,Ios,Objective C,Uilabel,我有两门课,客户端\u主和客户端\u演示 在Client\u Main类中,我使用一个显示客户端名称的标签,单击Client\u Main类中的按钮后,我添加了Client\u demo类作为子视图。现在,当我点击Client\u demo类上的按钮时,我想更改Client\u Main类标签的文本 因此,请建议我如何执行此操作。在superview中为UILabel添加一个唯一的标记 [超级视图子视图]返回superview中的所有视图对象,并从中获取具有您设置的唯一标记的对象,即它 for

我有两门课,客户端\u主客户端\u演示
Client\u Main类中,我使用一个显示客户端名称的标签,单击Client\u Main类中的按钮后,我添加了Client\u demo类作为子视图。现在,当我点击Client\u demo类上的按钮时,我想更改Client\u Main类标签的文本


因此,请建议我如何执行此操作。

在superview中为
UILabel
添加一个唯一的标记

[超级视图子视图]返回superview中的所有视图对象,并从中获取具有您设置的唯一标记的对象,即它

 for (UILabel *label in [yourSubview.superview]) {
        if (label.tag==uniqueID) {
            //Here is your uilabel instance ,do what you want
        }
    }

正确的方式:授权

只需在superview上创建一个带有实现的委托方法,以使用其实例在标签上进行更改。 从子视图类中激发委托方法


从子视图更新superview有两种方法 1-通过通知 在这种方法中,您必须在superview calass中创建通知,并像这样设置观察者

//you can write this code in viewDidLoad 

  [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(notificationEventForUpdateData:)   name:@"NotificationForUpdateHomeScreenData" object:nil];

and define this method notificationEventForUpdateData in same superview class in this method    you can update label textfield etc whatever you want 

 -(void) notificationEventForUpdateData: (NSNotification *)notification
 {
     self.label.text=@"newvalue";
 }
在子视图中,您必须从要更新的操作(内部方法)发布此通知,如按钮单击或表格视图的单元格选择等 这样

   [[NSNotificationCenter defaultCenter]
 postNotificationName:@"NotificationForUpdateHomeScreenData" 

双向授权是正确的

查看此处您应该通过响应者链向视图控制器发送一条操作消息。然后,作为对操作消息的响应,视图控制器应该根据需要配置视图。