trying to update a UILabel on a parent view controller when dismissing the modal view

前端 未结 3 754
北海茫月
北海茫月 2020-12-06 21:53

I am trying to update a UILabel in a parent View after someone makes a change in a modal view. So, after they click \"save\" ... the newly entered value would change what t

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 22:19

    in SWIFT:

    ParentViewController :

        func updateLabel() {
            yourLabel.text! = "what you need"
        }
    
    override func viewDidLoad() {
            super.viewDidLoad()
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.updateLabel), name: "DoUpdateLabel", object: nil) 
    }
    

    In OtherView:

    @IBAction func closePopUp(sender: AnyObject) {
    
           NSNotificationCenter.defaultCenter().postNotificationName("DoUpdateLabel", object: nil, userInfo: nil)
        }
    

提交回复
热议问题