iOS5 Storyboard UIPageViewController

标签 ios ipad storyboard uisplitviewcontroller uipageviewcontroller

我正在开发一个应用程序,我正在使用 iOS5 Storyboard。基本上我所拥有的是一个 UITabBarController 作为根 Controller ,其中包含一些 UIViewController 和一个 UISplitViewController。我想要做的是使用 UIPageViewController 作为 UISplitViewController 的 DetailController。问题是 UIPageViewController 没有显示它的 View Controller ,但它显示了一个黑屏。我所做的是在 DetailController 的 viewDidLoad 方法中初始化两个内容 View Controller ,并为其分配指令:
[self setViewControllers:self.pagesViewControllerArray direction:UIPageViewControllerNavigationOrientationHorizontal animated:NO completion:nil];
所以我无法弄清楚错误在哪里。

viewDidLoad 方法如下:

- (void)viewDidLoad{

    self.dataSource = self;
    self.delegate = self;

    self.page1ViewController = [[Page1ViewController alloc] initWithNibName:@"Page1ViewController" bundle:nil];
    self.page2ViewController = [[Page2ViewController alloc] init];

    self.pagesViewControllerArray = [NSArray arrayWithObjects:self.page1ViewController, self.page2ViewController, nil];

    [self setViewControllers:self.pagesViewControllerArray direction:UIPageViewControllerNavigationOrientationHorizontal animated:NO completion:nil];

} 

我尝试同时使用带有 nib 关联的 View Controller 和动态加载 View 的 View Controller ,但它不起作用。

任何帮助将非常感激。
谢谢

最佳答案

首先确保正在调用 viewDidLoad。初始化实例的方法有很多种,我不确定何时使用每个选项。如果我没记错的话,如果使用了 initWithNibName ,那么 viewDidLoad 将不会被调用。为了确保调用该方法,您可以添加一个 NSLog 语句,例如...

NSLog(@"viewDidLoad: %@", NSStringFromClass([self class]));

如果正在调用它,它将显示在调试器控制台中。您还可以添加 initWithNibName 方法以查看是否调用了该方法。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSLog(@"initWithNibName: %@", NSStringFromClass([self class]));
    }
    return self;
}

我发现 Storyboard 并没有像我预期的那样工作。我开始使用的是容器 View 。他们没有什么花哨的。它们只是您可以放置​​在 View 中的视觉元素,然后将其包装在标准 UIViewController 周围,然后设计图面会显示与您放置在另一个 View 中的容器 View 具有相同尺寸的相关 View 。然后您可以在那里管理详细信息。如果您确实需要使用父 View Controller 处理任何初始化,您将使用 prepareForSegue 方法。您需要为容器 View 设置嵌入转场的名称(不是您通常看到的推送转场),当它触发时,您可以访问destinationViewController,它只是容器 View 内的嵌入式 View Controller 。可能需要一些修补才能弄清楚。

还要在 Organizer 的 Documentation 选项卡中查找 UIPageViewController。左栏底部列出了一个示例项目,您可能会发现它很有用。

关于iOS5 Storyboard UIPageViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9838194/

相关文章:

ios - 在 IOS 的 Facebook 上发帖时出现错误

iphone - 当我在 UISplitViewController 中将 iPad 切换为纵向模式时,调整detailViewController的pagecontrolview的大小

iphone - NSTimer - 创建了多个实例

ios - iOS 中的手电筒闪光灯

ios - 我可以在我的 Storyboard的第二个 View 中启动我的 iOS 应用程序并使用 Unwind Segue 吗?

c# - 如何将 Storyboard用于 1 个以上的目标对象?

swift - 在 iOS 13 上,导航栏的内容在模式中部分不可见

ios - 使用 IB 更改 UISegmented Control 的高度?

ios - 可重用 UITableViewCell 与 UICollectionViewCell

javascript - iPhone 4+ 默认为 320 像素的网络应用程序分辨率,我想使用完整的 640 像素