0

我正在为 iPad 制作电子书。这本书的每一页都是应用程序 StoryBoard 中的一个视图控制器,它们的页码在 Interface Builder 中设置为它们的标识符。我正在研究实现导航的类,其作用是呈现和关闭视图控制器。它通过在呈现的视图控制器上覆盖一组按钮并处理它们的 IBAction 来实现。

我的问题是某些视图控制器(偶数页)从未出现过!谁能明白为什么?

@implementation Navigator

UIViewController *currentPageVC;
UIViewController *nextPageVC;

int currentPage = 0;

-(void)viewDidLoad{
    [self getLandingPage];
}

-(void)getLandingPage{

    currentPageVC = [self.storyboard instantiateViewControllerWithIdentifier:@"Landing"];
    currentPage = 0;
    NSLog(@"Trying to present landing page");
}

-(IBAction)goToNextPage{

    [currentPageVC dismissModalViewControllerAnimated:YES];
    currentPage++;    

    nextPageVC = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%d", currentPage ]];
    [self presentModalViewController:nextPageVC animated:YES];

    [nextPageVC.view addSubview:self.view];

    currentPageVC = nextPageVC;

    NSLog(@"Current Page is %d", currentPage);
}
4

1 回答 1

0

好的,修好了。发生这种情况是因为presentModalViewController:不久之后发生的电话dismissModalViewControllerAnimated:

为了解决这个问题,你必须使用它的新版本:dismissViewControllerAnimated:completion:

-(IBAction)goToNextPage{    
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"dismissed!");
        currentPage++;
        UIViewController *nextPageVC = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%d", currentPage ]];
        [self presentModalViewController:nextPageVC animated:YES];
        [nextPageVC.view addSubview:self.view];

        NSLog(@"Current Page is %d", currentPage);

    }];

}
于 2012-06-26T15:44:00.463 回答