触发按钮以更改 swift3 xcode 8 ios 10 中 UITextView 中的文本
问题描述:
我是 xcode 的新手,一直在解决这个问题,因为在网上尝试了几个示例代码示例后,没有任何效果.
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?
我的代码如下:
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"
}
}
答
你可以试试下面的代码,你肯定会得到你期望的输出,并确保你将故事板连接到你的视图控制器类,你按钮动作和文本文件插座可以适当地给IBActions和IBOutlets
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
未点击按钮前的输出
点击按钮后