根据按钮更改视图控制器中的信息

时间:2016-10-16 18:28:49

标签: ios swift uiviewcontroller

MenuViewController我有2个按钮 - 周和月。我也有CalendarViewController的segue,它现在只包含有关月份的信息。如何根据按下的其中一个按钮更改信息? 我尝试在MenuViewController上使用:

   @IBAction func buttonClick(sender: AnyObject) {

            let calendarVC = kConstantObj.SetIntialMainViewController("CalendarViewController")
            self.window?.rootViewController = calendarVC
            self.window?.makeKeyAndVisible()
            }

        if sender  == mounthButton {
               CalendarViewController.presentationMode(.MonthView)

        } else {

CalendarViewController.presentationMode(.WeekView)
}
}

并且在CalendarViewController上我有一个函数:

  func presentationMode() -> CalendarMode {
            return CalendarMode.MonthView
        }

但是出现错误'使用即时会员' presentationMode'在类型' CalendarViewController' ,你的意思是使用类型' CalendarViewController'代替'?

1 个答案:

答案 0 :(得分:0)

您正在尝试将演示模式设置为CalendarViewController类,而不是您实例化的CalendarViewController:calendarVC

你在哪里

CalendarViewController.presentationMode(.MonthView)

改为

calendarVC.presentationMode(.MonthView)

为.WeekView行做同样的事情

另外我认为最好打电话给'makeKeyAndVisible'设置presentationMode后