从另一个班级访问IBOutlet&更新UILabel

时间:2017-01-15 00:33:21

标签: ios swift protocols nsnotificationcenter

让我解释一下我的问题。我有2个ViewControllers。在第一个VC中,我想要从第二个VC更新一些标签(以模态方式呈现) enter image description here

enter image description here

此外我还有解散第二个VC的功能

@IBAction func approveDepart(_ sender: UIButton) {
    removeAnimate()

}

&安培;变量与日历中存储的数据

var someString: String?

在此功能中:

func calendar(_ calendar: MDCalendar, didSelect date: Date?) {
    let today = date

    //Date For API
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-d"
    let apiDate: NSString = dateFormatter.string(from: today!) as NSString

    //Date for week day
    let dateFormatter1 = DateFormatter()
    dateFormatter1.dateFormat = "EEE"
    let weekDay: NSString = dateFormatter1.string(from: today!) as NSString

    //Date for week number
    let dateFormatter2 = DateFormatter()
    dateFormatter2.dateFormat = "dd"
    let weekNumber: NSString = dateFormatter2.string(from: today!) as NSString

    //Date for month name
    let dateFormatter3 = DateFormatter()
    dateFormatter3.dateFormat = "MMM"
    let monthName: NSString = dateFormatter3.string(from: today!) as NSString

    someString = weekDay as String


}

任何想法如何实现? :)

1 个答案:

答案 0 :(得分:-1)

找到解决方案:)

let rootViewController = UIApplication.shared.keyWindow?.rootViewController

    if let customViewController = rootViewController as? ChoseFlyView {

        customViewController.departDay.text = someString
    }