سؤال

Hi I have a uiviewcontroller that adds 4 childviews after receiving data from a webservice. I add an observer to the uiviewcontroller that watches when the data is completely loaded from the webservice. Once it is, the uiviewcontroler adds 4 childviews.

however my problem is it doesn't do this unless i switch to another tab view than go back to that tab again.

Is there a way to reload this page? I used [uiviewcontroller.view setNeedsDisplay] under the function that responds to the notification from the observer but the view doesn't refresh.

thanks for your guys' help :)

here is my observer function:

 -(void)projectListFromServer:(NSNotification *) response

{
NSLog(@"%@",response);


for (int i = 0; i < 4; i++)
{
    childview2 = [self.storyboard instantiateViewControllerWithIdentifier:(@"slider")];
    childview2.image = @"wicked";
    childview2.couponID = @"cool";

    NSLog(@"%@", self.childview2.couponID);
    [self addChildViewController:childview2];
}

 [self.childview.view setNeedsDisplay];


}
هل كانت مفيدة؟

المحلول

You are calling addChildViewController, but then it looks like you aren't actually adding childview2's view hierarchy to this containing view controller's view hierarchy.

You'll need to do something like this, adjusted of course depending on where in your current hierarchy you actually want these new views to be inserted:

[self addChildViewController:self.childview2]; // assuming childview2 is a @property
[self.view addSubview:self.childview2.view]; // adjust based on your actual hierarchy
[self.childview2 didMoveToParentViewController:self];  

BTW, you should avoid giving view controllers names like childview2. Views and view controllers are two completely different things.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top