Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从另一个类访问IBOutlet&;更新UILabel_Ios_Swift_Protocols_Nsnotificationcenter - Fatal编程技术网

Ios 从另一个类访问IBOutlet&;更新UILabel

Ios 从另一个类访问IBOutlet&;更新UILabel,ios,swift,protocols,nsnotificationcenter,Ios,Swift,Protocols,Nsnotificationcenter,让我解释一下我的问题。我有两个视图控制器。在第一个VC中,我想从第二个VC更新一些标签(以模式显示) 我还有一个函数,它可以解散第二个VC @IBAction func approveDepart(_ sender: UIButton) { removeAnimate() } &带有日历中存储的数据的变量 var someString: String? 在该功能中: func calendar(_ calendar: MDCalendar, didSelect date: Da

让我解释一下我的问题。我有两个视图控制器。在第一个VC中,我想从第二个VC更新一些标签(以模式显示)

我还有一个函数,它可以解散第二个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


}
有什么办法可以做到这一点吗?:)

找到了解决方案:)


@瓦卡瓦马,是你!我将阅读这篇文章,它本质上违反了,访问了另一个类中的内容。调用方不应该知道被调用的类实例如何处理数据,而应该导出一个方法来进行更改。现实世界的例子:向朋友要一美元,不要伸手到他的口袋里去拿,即使你的朋友把钱放在哪里,你也不应该去拿。
let rootViewController = UIApplication.shared.keyWindow?.rootViewController

    if let customViewController = rootViewController as? ChoseFlyView {

        customViewController.departDay.text = someString
    }