Trigger button to change text in UITextView in swift3 xcode 8 ios 10

青春壹個敷衍的年華 提交于 2021-01-27 12:23:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!