我正在为iPad制作电子书。本书的每一页都是应用程序StoryBoard中的View Controller,其页码在Interface Builder中设置为其标识符。我正在研究实现导航的类,其作用是呈现和关闭视图控制器。它通过在呈现的视图控制器上叠加一组按钮并处理它们的IBActions来实现。
我的问题是一些视图控制器(偶数页面)永远不会出现!谁能明白为什么?
@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);
}
答案 0 :(得分: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);
}];
}