我有一个像这样设置的课程
class CardItemController: UIViewController,UIPageViewControllerDataSource
取决于项索引,我需要使用不同的UIViewController子类,如
private func getItemController(itemIndex:Int) - > SuperUIPageController? {
if itemIndex < cards.count {
if itemIndex == 0{
let pageItemController = CardImagePageController()
pageItemController.itemIndex = itemIndex
pageItemController.labelText = labelText
//pageItemController.screenWidth = self.frame.width
return pageItemController
}else{
let pageItemController = CardController()
pageItemController.itemIndex = itemIndex
pageItemController.labelText = labelText
//pageItemController.screenWidth = self.frame.width
return pageItemController
}
}
return nil
}
CardController和CardImagePageController看起来像这样
class CardController: SuperUIPageController {
class CardImagePageController: SuperUIPageController,UIPageViewControllerDataSource {
根据索引,使用不同的UIViewControllers的正确方法是什么?现在我得到各种各样的错误,比如 在CardImagePageController我得到:
Type 'CardImagePageController' does not conform to protocol 'UIPageViewControllerDataSource'
当我有这些方法时
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
private func getItemController(itemIndex: Int) -> CardImageController? {
答案 0 :(得分:0)
在此处检查UIPageViewController代码的示例:https://github.com/dimpiax/UIPageViewControllerScrolling