无法修改从storyboard添加到PageViewController的viewControllers的UI?

时间:2015-07-04 14:53:43

标签: ios objective-c iphone uiviewcontroller

我有一个PageViewController,我想在其中添加一些"卡"(ViewController)。每张卡片都需要一页。卡片的ViewController需要从故事板中实例化,因为我已经设置了一些UIOutlet。

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    //Get info of the former page
    ZDMainCardsViewController *formerVC = (ZDMainCardsViewController *)viewController;
    //Use a property to mark VC's number
    NSInteger formerIndex = formerVC.cardIndex;

    //Init from Storyboard
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"ZDMain" bundle:[NSBundle mainBundle]];
    UIViewController *cardsVC = [sb instantiateViewControllerWithIdentifier:@"ZDMainCardsCollectionViewController"];

    //Set this VC
    ZDMainCardsViewController *thisVC = (ZDMainCardsViewController *)cardsVC;

    //Fill data according to VC's number.
    //In the beginning I tried to do this in viewDidLoad by using self.cardIndex
    //That turns to be useless, and I add a method to do so
    //Though, it's useless too
    [thisVC loadNextCard:formerIndex];
    return thisVC;
}

代码和我的目标如上所示。现在的结果是每张卡都是一样的。断点显示VC.cardIndex永远不会改变。在loadNextCard方法中,self.oneLabel.text = data没有效果。

1 个答案:

答案 0 :(得分:0)

可能您在初始化之前尝试访问ViewController的出口。 当您显示此视图控制器或访问其view属性时,View Controller的视图会被延迟加载。

在访问其商店之前尝试检查viewController.isViewLoaded媒体资源,并在需要时致电[viewController loadView]或致电[viewController view]

  

VC.cardIndex永远不会改变

您是否忘记增加索引?

[thisVC loadNextCard:formerIndex + 1];