草庐IT

ios - UIPageViewController 与多个 UIViewController 与标题和底栏

coder 2024-01-24 原文

我用多个 UIViewController 做了一个 UIPageViewController。现在,我需要在 UIPageViewController 的顶部和底部添加一个固定的 UIView...

这是我的代码:

   - (void)viewDidLoad
{
    [super viewDidLoad];

    // Create it.
    self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

    // Point the datasource back to this UIViewController.
    self.pageController.dataSource = self;

    // Assuming you have a SomePageViewController which extends UIViewController so you can do custom things.


    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    if(!self.roteirosView)
        self.roteirosView = [sb instantiateViewControllerWithIdentifier:@"RoteirosView"];

    self.initialViewControllers = [NSArray arrayWithObject:self.roteirosView];

    // animated:NO is important so the view just pops into existence.
    // direction: doesn't matter because it's not animating in.
    [self.pageController setViewControllers:self.initialViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

    // Tell the child view to get ready
    [self.pageController willMoveToParentViewController:self];

    // Actually add the child view controller
    [self addChildViewController:self.pageController];

    // Don't forget to add the new root view to the current view hierarchy!
    [self.view addSubview:self.pageController.view];

    // And make sure to activate!
    [self.pageController didMoveToParentViewController:self];
}

- (void)viewDidLayoutSubviews {
}

- (UIViewController *)viewControllerAtIndex:(int)i {
    // Asking for a page that is out of bounds??
    if (i<0) {
        return nil;
    }
    if (i>=MAX_PAGES) {
        return nil;
    }

    // Assuming you have SomePageViewController.xib
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    if (i == 0) {
        if(!self.roteirosView)
            self.roteirosView = [sb instantiateViewControllerWithIdentifier:@"RoteirosView"];
        return self.roteirosView;
    }
    else {
        if(!self.pertoView)
            self.pertoView = [sb instantiateViewControllerWithIdentifier:@"PertoView"];
        return self.pertoView;
    }
}


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
    UIViewController *p = (UIViewController *)viewController;
    if ([p isKindOfClass:[PertoViewController class]]) {
        return [self viewControllerAtIndex:0];
    }
    else {
        return [self viewControllerAtIndex:MAX_PAGES]; // permanece na mesma página
    }

}


- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    UIViewController *p = (UIViewController *)viewController;
    if ([p isKindOfClass:[PertoViewController class]]) {
        return [self viewControllerAtIndex:MAX_PAGES]; // permanece na mesma página
    }
    else {
        return [self viewControllerAtIndex:1];
    }
}

在我的 UIStoryBoard 中,我有 HomesViewController,它是我的 UIPageViewController、PertoViewController 和 RoteirosViewController。两个UIViewControllers都加入了UIPageViewController

最佳答案

在 UIPagerViewController 类的 viewDidAppear 中添加您要添加​​的 2 个 UIView,这应该在 2 个 View Controller 的已加载 View 上添加新 View 。

如果这对您不起作用,请确保您也通过代码而不是 Storyboard 中的代码添加 2 View Controller ,并确保先添加它们,然后添加 2 View 标题和底部 View 以确保它们在屏幕上

希望这个回答能帮到你,祝你好运

关于ios - UIPageViewController 与多个 UIViewController 与标题和底栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31965739/

有关ios - UIPageViewController 与多个 UIViewController 与标题和底栏的更多相关文章

  1. ruby-on-rails - Rails 3 中的多个路由文件 - 2

    Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题

  2. ruby-on-rails - 在 Ruby 中循环遍历多个数组 - 2

    我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代

  3. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  4. ruby - 多个属性的 update_column 方法 - 2

    我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2

  5. ruby-on-rails - 在 ruby​​ .gemspec 文件中,如何指定依赖项的多个版本? - 2

    我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这

  6. ruby-on-rails - 使用 Rmagick 或 ImageMagick 在背景上放置标题 - 2

    我有一张背景图片,我想在其中添加一个文本框。我想弄清楚如何将标题放置在其顶部的正确位置。(我使用标题是因为我需要自动换行功能)。现在,我只能让文本显示在左上角,但我需要能够手动定位它的开始位置。require'RMagick'require'Pry'includeMagicktext="Loremipsumdolorsitamet"img=ImageList.new('template001.jpg')img 最佳答案 这是使用convert的ImageMagick命令行的答案。如果你想在Rmagick中使用这个方法,你必须自己移植

  7. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  8. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  9. ruby - 使用多个数组创建计数 - 2

    我正在尝试按0-9和a-z的顺序创建数字和字母列表。我有一组值value_array=['0','1','2','3','4','5','6','7','8','9','a','b','光盘','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','','u','v','w','x','y','z']和一个组合列表的数组,按顺序,这些数字可以产生x个字符,比方说三个list_array=[]和一个当前字母和数字组合的数组(在将它插入列表数组之前我会把它变成一个字符串,]current_combo['0','0','0']

  10. ruby-on-rails - before_filter 运行多个方法 - 2

    是否有可能:before_filter:authenticate_user!||:authenticate_admin! 最佳答案 before_filter:do_authenticationdefdo_authenticationauthenticate_user!||authenticate_admin!end 关于ruby-on-rails-before_filter运行多个方法,我们在StackOverflow上找到一个类似的问题: https://

随机推荐