Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Update UILabel from Another ViewController
    text
    copied!<p>I'm using Storyboards and iOS 6.1, I'm initiating a view like this:</p> <pre><code>PropertiesViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Properties"]; </code></pre> <p><code>PropertiesViewController</code> has a 60px height viewn an including some labels and more. I want to add these views to another <code>ScrollView</code> as subview. Here what I'm doing:</p> <pre><code>controller.leftLabel.text = @"Test"; controller.background.image = [UIImage imageNamed: @"someimage.png"]; controller.view.frame = CGRectMake(0, currentHeight, controller.view.frame.size.width, cellHeight); [self.scrollView addSubview: controller.view]; </code></pre> <p>leftLabel is a <code>UILabel</code> and backgorund is a <code>UIImageView</code>.The problem is none of view's elements are not updating outside of <code>PropertiesViewController</code>. <code>addSubview:</code> is just adding as how its created, not allow to configure.</p> <p>I've already checked <code>NSNotificationCenter</code> approach, if I'm not wrong it's not about updating instances. And I've also already added a method to receiver class to update labels inside of <code>PropertiesViewController</code>. That even did not worked.</p> <p>What am I doing wrong? </p> <p><strong>Note</strong>: You may ask that why just I'm not using a <code>TableView</code>. There has to be more dynamic resources and their besides are not clear. There is also one thing that TableView is not possible with ScrollView, in some cases I've never use a TableView so scrollview will manage scroll. </p> <p>Any help would be great.</p> <p><strong>EDIT:</strong></p> <p>According to Kalpesh's answer here what I did:</p> <p>In my sender view controller:</p> <pre><code>PropertiesViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Properties"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"update" object:@"Test string"]; controller.view.frame = CGRectMake(0, currentHeight, controller.view.frame.size.width, cellHeight); // not sure how but I can change frame successfully. [self.scrollView addSubview: controller.view]; </code></pre> <p>Here is receiver:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"Called"); // Working fine [[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changetext:) name:@"update" object:nil]; //even if set some object, nothing changed } - (void) changetext:(NSNotification *)notification { NSLog(@"Received"); // Not working leftLabel.text = [notification object]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload