如何从另一个ViewController更新UILabel

我正在使用Storyboard和iOS 6.1,我正在启动一个这样的视图:

PropertiesViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Properties"]; 

PropertiesViewController有一个60px高度的视图,包括一些标签和更多。 我想将这些视图添加到另一个ScrollView作为子视图。 这里我在做什么:

 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]; 

leftLabel是UILabel ,backgorund是UIImageView 。问题是没有视图的元素不在PropertiesViewController之外更新。 addSubview:只是添加如何创build,不允许configuration。

我已经检查了NSNotificationCenter方法,如果我没有错,它不是关于更新实例。 而且我也已经添加了一个方法给接收器类来更新PropertiesViewController标签。 这甚至没有奏效。

我究竟做错了什么?

注意 :您可能会问,为什么我不使用TableView 。 必须有更多的dynamic资源,除此之外还不清楚。 还有一件事,TableView不可能与ScrollView,在某些情况下,我从来没有使用TableView,所以滚动视图将pipe理滚动。

任何帮助将是伟大的。

编辑:

根据Kalpesh在这里的回答我做了什么:

在我的发件人视图控制器:

 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]; 

这是接收器:

 - (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]; } 

试试这个,当你想改变文本标签时,你必须从其他viewcontroller发送通知。

  [[NSNotificationCenter defaultCenter] postNotificationName:@"changetext" object:stringobj]; 

在mainviewcontroller

  -(void)viewDidLoad { [[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changetext:) name:@"changetext" object:nil]; } - (void) changetext:(NSNotification *)notification { NSString * text =[notification object]; lbl.text=text; }