I have got two views. first ist "homeView" the second is "detailView".
in homeView i have two buttons button1 button2
in detailView i have on label label1
when i push button1 the should change to "detailView" an the label1.text should be "button 1 gedrückt" when i push button2 the should change to "detailView" an the label1.text should be "button 2 gedrückt"
when i use the code:
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBAction func button1(sender: UIButton) {
let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("detailview")
self.showViewController(vc as! UIViewController, sender: vc)
// self.label1.text = "button 1 gedrückt"
}
the view will change, but the label1.text won´t change. if i use
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBAction func button1(sender: UIButton) {
let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("detailview")
self.showViewController(vc as! UIViewController, sender: vc)
self.label1.text = "button 1 gedrückt"
}
i don´t know what i can do??
Thanks too all. now i can change the text in label1 with this code
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "segueTest") {
let svc = segue.destinationViewController as! SecondViewController;
svc.toPass = label2.text
}
}
now another question? can i put this "override func" into IBAction? because i want to add more buttons. with every button there should be another text in the label1.
Thanks (i´m an absolut beginner in Xcode and swift)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.