0

I have two class, Client_Main and Client_demo.
In Client_Main class I am using a label which shows client name and after click on a button from Client_Main class I have added Client_demo class as a subview. Now when I click on a button on Client_demo class I want to change the text of Client_Main class label.

So please suggest me how to do this.

Ahmed Z.
  • 2,329
  • 23
  • 52
user2388607
  • 51
  • 1
  • 5
  • take a look here http://www.roostersoftstudios.com/2011/04/12/simple-delegate-tutorial-for-ios-development/ – jamil May 16 '13 at 06:19
  • You should send an action message via the responder chain to your view controller. Then your view controller in response to your action message should configure your views as appropriate. – nielsbot May 16 '13 at 07:11

2 Answers2

0

Put an unique tag for the UILabel in superview

[superview subviews]; returns all the view objects in the superview and from that get the one with the unique tag you set and that is it

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

OR

The proper way : Delegation

just make a delegate method with implementation on the superview to change on label using its instance. Fire the delegate method from the subview class

more on delegation

Community
  • 1
  • 1
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
0

there is two way to update superview from subview 1-Via NSNotification in this approch you have to create notification in superview calass and set observer like this

//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";
 }

from subview you have to post this notification from that action(inside method ) you want to update like button click or cell selection of table view etc like this way

   [[NSNotificationCenter defaultCenter]
 postNotificationName:@"NotificationForUpdateHomeScreenData" 

2- way is Proper delegation

Anupam
  • 555
  • 1
  • 5
  • 14