Ios 从其他视图控制器访问IBOutlet按钮

Ios 从其他视图控制器访问IBOutlet按钮,ios,swift,Ios,Swift,我需要访问并更改另一个视图控制器上存在的按钮的标题。这可能吗?如果是,我如何才能做到这一点 视图控制器1: Class Home: UIViewController { @IBOutlet weak var testBTN: UIButton! } ViewController 2: Home.testBTN // does not work I can't access the button from here 我想我在目标C中找到了解决方案,但我不知道如何在swift中实现这一点

我需要访问并更改另一个视图控制器上存在的按钮的标题。这可能吗?如果是,我如何才能做到这一点

视图控制器1:

Class Home: UIViewController
{
   @IBOutlet  weak var testBTN: UIButton!
}
ViewController 2:

Home.testBTN // does not work I can't access the button from here
我想我在目标C中找到了解决方案,但我不知道如何在swift中实现这一点 VC 2(发送通知):

VC 1(接收和更新):

在viewDidLoad中:

let updateNotificationString = "com.yourcompany.yourapp.updatebutton"
NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateButton", name: updateNotificationString, object: nil)
然后创建一个函数:

func updateButton() {
    testBTN.setTitle("New Title", forState: UIControlState.Normal)
}
func updateButton() {
    testBTN.setTitle("New Title", forState: UIControlState.Normal)
}