【发布时间】:2015-07-04 14:53:43
【问题描述】:
我有一个 PageViewController,我想在其中添加一些“卡片”(ViewController)。每张卡片将占用一页。卡片的 ViewController 需要从 storyboard 中实例化,因为我已经设置了一些 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 运行没有任何效果。
【问题讨论】:
标签: ios objective-c iphone uiviewcontroller