'CASPageMenu'类型的值没有会员'currentPageIndex'

时间:2016-05-01 06:59:30

标签: swift

我是初学者,其次是开源框架正在做,但这一步并不知道问题出在哪里。

public class CAPSPageMenu: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
    ...
    var currentPageIndex : Int = 0
    ...
}

var pageMenu : CAPSPageMenu?
func didTapGoToLeft() {
   var currentIndex = pageMenu!.currentPageIndex  # error

   if currentIndex > 0 {
        pageMenu!.moveToPage(currentIndex - 1)
   }
}
  

错误消息:'CASPageMenu'类型的值没有成员'currentPageIndex'

谢谢!

2 个答案:

答案 0 :(得分:1)

你必须初始化pageMenu,否则它不知道它会有多少页面。

你写的这句话还不够:

var pageMenu : CAPSPageMenu?

写完之后:

var pageMenu : CAPSPageMenu?

override func viewDidAppear(animated: Bool) {             
    super.viewDidAppear(animated)

viewDidAppear 中,你可以添加:

// MARK: - Scroll menu setup

// Initialize view controllers to display and place in array
var controllerArray : [UIViewController] = []
let controller1 : UIViewController! = UIViewController()
controller1.title = "TEST1"
controllerArray.append(controller1)
let controller2 : UIViewController! = UIViewController()
controller2.title = "TEST2"
controllerArray.append(controller2)
// Initialize scroll menu
// Customize menu (Optional)

let parameters: [CAPSPageMenuOption] = [.ScrollMenuBackgroundColor(UIColor(red: 30.0/255.0, green: 30.0/255.0, blue: 30.0/255.0, alpha: 1.0)),.ViewBackgroundColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 1.0)),
            .SelectionIndicatorColor(UIColor.orangeColor()),
            .BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
            .MenuItemFont(UIFont(name: "HelveticaNeue", size: 13.0)!),
            .MenuHeight(40.0),
            .MenuItemWidth(90.0),
            .CenterMenuItems(true)
]
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width,self.view.frame.height), pageMenuOptions: parameters)
self.addChildViewController(pageMenu!)
self.view.addSubview(pageMenu!.view)
pageMenu!.didMoveToParentViewController(self)

现在当你didTapGoToLeft() pageMenu确切知道他当前的页面,总页数,上一页和下一页要去的地方..

答案 1 :(得分:0)

替换:

    var pageMenu : CAPSPageMenu?
func didTapGoToLeft() {
   var currentIndex = pageMenu!.currentPageIndex  # error

   if currentIndex > 0 {
        pageMenu!.moveToPage(currentIndex - 1)
   }
}

使用:

func didTapGoToLeft() {
   if let currentIndex = CAPSPageMenu.currentPageIndex { 
       if currentIndex > 0 {
           self.moveToPage(currentIndex - 1)
       }
   }
}

看看它现在是否有效。