以编程方式导航到基于事件的页面界面中的后页

navigate to back page in page based interface on event programmatically

我的应用程序是基于页面的,我想在一个事件中我的应用程序滑动到左页 programmatically.i 尝试使用 becomeCurrentPage 方法,但在这种情况下如何使用它。 请帮忙。 任何建议将不胜感激。 谢谢

becomeCurrentPage 是以编程方式更改当前页面的唯一方法,因此您走在正确的轨道上。但是,听起来您需要从一个页面到另一个页面进行通信。

假设您的界面控制器知道它自己的页面索引(您可以将其传递给 awakeWithContext:),您可以通过发送自定义通知来完成此操作:

NSDictionary *userInfo = @{ @"page" : @(MAX(self.pageIndex - 1, 0)) };
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyChangePageNotification"
                                                        object:nil
                                                      userInfo:userInfo];

然后,在每个控制器中,确保您正在监听通知:

[[NSNotificationCenter defaultCenter]
 addObserverForName:@"MyChangePageNotification"
 object:nil
 queue:nil
 usingBlock:^(NSNotification *note) {

     // Are we supposed to become the current page?
     if (self.pageIndex == [note.userInfo[@"page"] integerValue]) {
         [self becomeCurrentPage];
     }
 }];

基本上,每个页面都会监听您的自定义通知,当传递的页面索引与控制器的索引匹配时,它就会成为当前页面。