简体   繁体   中英

UIPageViewController - flip to random page takes lot of time

Am developing an iPhone App, that's page-based. Now, on click of a button, am flipping to a random page. On flipping, the new page's viewDidAppear is called first, & then the current page's viewDidDisappear is called (this is expected behavior). The new page appears quickly (I put a print of [NSDate date] in the viewDidAppear), but the 'viewDidDisappear' of the current page is called after, on an average, 30 to 40 seconds after the viewDidAppear of the new page (& no other method is called in between ; I put NSLog in each method to see if something else is getting called) ! So it's like this: 1. viewDidAppear of the new page is called & ends (I checked this with printing the start & end time of the viewDidAppear) almost immediately 2. nothing is happening for almost 30 to 40 seconds ('after' viewDidAppear of the new page 'ends' ) 3. Then, viewDidDisappear of the current page is called ! (& i have no processing in viewDidDisappear / viewWillDisappear ; am just printing the current time)

Why is there such a long pause in between?

This is my relevant code snippet: (environment: XCode 4.3, iOS 5.0, testing with iPad)

The code which turns to random page:

NSMutableArray *array = [[NSMutableArray alloc] init];
ViewController_EachPage *page = [self getPageAtIndex:randomPageNum];
if ((page != nil) && (page != NULL)) {
    [array insertObject:page atIndex:0];
}
[self.viewCtrlrPages 
     setViewControllers:[NSArray arrayWithArray:array]  
    direction:UIPageViewControllerNavigationDirectionForward 
     animated:YES completion:nil];

The viewDidAppear method

....
self.timer = [NSTimer scheduledTimerWithTimeInterval:10.0f
                target:self selector:@selector(hideThem)
                userInfo:nil repeats:NO];   

[((com_AppDelegate *) [[UIApplication sharedApplication] delegate]).viewCtrlrCoverPage.viewCtrlrPages initializePage];

NSLog(@"EachPage.viewDidAppear at %@", [NSDate date]);
....

The viewDidDisappear method

-(void) viewWillDisappear:(BOOL)animated {
    NSLog(@"EachPage.viewWillDisappear");
    [self.timer invalidate];
}

-(void) viewDidDisappear:(BOOL)animated {
    NSLog(@"EachPage.viewDidDisappear at %@", [NSDate date]);
}

您无法在viewWillAppear / viewWillDisappear等中调用超级。不好的主意。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM