2

ストーリーボードと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です。問題は、ビューの要素が。の外部で更新されていないことですPropertiesViewControlleraddSubview:作成方法として追加するだけで、構成は許可されません。

私はすでに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];
}
4

1 に答える 1

5

これを試してください。テキストのラベルを変更する場合は、他のビューコントローラから通知を送信する必要があります。

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

 }
于 2013-02-13T11:31:27.870 に答える