ストーリーボードとiOS6.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はaUILabel
で、backgorundはUIImageView
です。問題は、ビューの要素が。の外部で更新されていないことですPropertiesViewController
。addSubview:
作成方法として追加するだけで、構成は許可されません。
私はすでにNSNotificationCenter
アプローチをチェックしました、私が間違っていなければ、それはインスタンスを更新することではありません。また、レシーバークラスにメソッドを追加して、内のラベルを更新しましたPropertiesViewController
。それもうまくいきませんでした。
私は何が間違っているのですか?
注:なぜ私が。を使用していないのかと疑問に思われるかもしれませんTableView
。より動的なリソースが必要であり、そのほかに明確ではありません。TableViewがScrollViewでは不可能なことも1つあります。場合によっては、TableViewを使用したことがないため、scrollviewがスクロールを管理します。
どんな助けでも素晴らしいでしょう。
編集:
ここでのカルペシュの答えによると、私がしたことは次のとおりです。
私の送信者ビューコントローラでは:
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];
}