2

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

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

PropertiesViewController有一个 60 像素的高度,包括一些标签等等。我想将这些视图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 是 aUILabel并且 backgorund 是UIImageView. 问题是视图的元素都没有在PropertiesViewController. addSubview:只是添加它的创建方式,不允许配置。

我已经检查过NSNotificationCenter方法,如果我没记错的话,这与更新实例无关。而且我还已经向接收器类添加了一个方法来更新PropertiesViewController. 那甚至没有用。

我究竟做错了什么?

注意:您可能会问为什么我不使用TableView. 必须有更多的动态资源,而且它们还不清楚。还有一件事是 ScrollView 无法使用 TableView,在某些情况下,我从未使用过 TableView,因此 scrollview 将管理滚动。

任何帮助都会很棒。

编辑:

根据 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];
}
4

1 回答 1

5

试试这个,当你想改变文本标签时,你必须从其他视图控制器发送通知..

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

在主视图控制器中

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

 }
于 2013-02-13T11:31:27.870 回答