Saturday, 15 May 2010

ios - setNeedsDisplay not working after adding subviews -



ios - setNeedsDisplay not working after adding subviews -

i added 500 views viewcontroller.view. action took 5 seconds on target. want screen refresh after each subview i'm adding, user see them appears 1 1 on screen.

i tried in viewcontroller:

-(void)viewdidappear:(bool)animated { [super viewdidappear:animated]; for(int i=0; i<500; i++) { //...create aview [self.view addsubview:aview]; [self.view setneedsdisplay]; } }

i run , nil happened 5 seconds views appeared @ once. made sure [self.view setneedsdisplay] called main thread context.

any thought how create subviews appear 1 one?

i found simple solution. added new property viewcontroller - 'subviewscount' witch initialised 500. called next method viewdidload:

-(void) addsubviewstomotherview { self.subviewscount -=1; if (self.subviewscount >= 0) { [uiview animatewithduration:0.0 delay:0.0 options:uiviewanimationoptionlayoutsubviews animations:^{ [self methodtoaddsubview]; } completion:^(bool finished){ [self addsubviewstomotherview]; } ]; } }

ios objective-c iphone addsubview setneedsdisplay

No comments:

Post a Comment