问题
I'm new to xcode and am stuck on this problem, because after trying several sample code examples online, nothing works.
Could you help me figure out what the problem is?
My code below:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var Writingboard: UITextView!
@IBOutlet weak var Talkbutton: UIButton!
@IBAction func TalkbuttonTapped(_ sender: AnyObject){
Talkbutton.setTitle("Tap to Stop", for: .normal)
Writingboard.text="talking"
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//Talkbutton.isEnabled=true
Writingboard.text="test the initializer"
}
}
回答1:
you can try this bellow code you definetly get the output what you expected and make sure you connect the story board to your view controller class you button action and textfiled outlets can give IBActions and IBOutlets properly
output before not button tapped
After tapped the button
来源:https://stackoverflow.com/questions/41324319/trigger-button-to-change-text-in-uitextview-in-swift3-xcode-8-ios-10