1. <i id='anp0e'><tr id='anp0e'><dt id='anp0e'><q id='anp0e'><span id='anp0e'><b id='anp0e'><form id='anp0e'><ins id='anp0e'></ins><ul id='anp0e'></ul><sub id='anp0e'></sub></form><legend id='anp0e'></legend><bdo id='anp0e'><pre id='anp0e'><center id='anp0e'></center></pre></bdo></b><th id='anp0e'></th></span></q></dt></tr></i><div id='anp0e'><tfoot id='anp0e'></tfoot><dl id='anp0e'><fieldset id='anp0e'></fieldset></dl></div>

    2. <legend id='anp0e'><style id='anp0e'><dir id='anp0e'><q id='anp0e'></q></dir></style></legend>
      • <bdo id='anp0e'></bdo><ul id='anp0e'></ul>

      <small id='anp0e'></small><noframes id='anp0e'>

    3. <tfoot id='anp0e'></tfoot>

        如何获取 Swift 3.0 中按钮的当前标题,ios 使用 sender.titleForState(.Normal)

        How to get the current Title of a button in Swift 3.0 , ios using sender.titleForState(.Normal)!(如何获取 Swift 3.0 中按钮的当前标题,ios 使用 sender.titleForState(.Normal)!)
        1. <i id='3EoXu'><tr id='3EoXu'><dt id='3EoXu'><q id='3EoXu'><span id='3EoXu'><b id='3EoXu'><form id='3EoXu'><ins id='3EoXu'></ins><ul id='3EoXu'></ul><sub id='3EoXu'></sub></form><legend id='3EoXu'></legend><bdo id='3EoXu'><pre id='3EoXu'><center id='3EoXu'></center></pre></bdo></b><th id='3EoXu'></th></span></q></dt></tr></i><div id='3EoXu'><tfoot id='3EoXu'></tfoot><dl id='3EoXu'><fieldset id='3EoXu'></fieldset></dl></div>
            <bdo id='3EoXu'></bdo><ul id='3EoXu'></ul>

            <legend id='3EoXu'><style id='3EoXu'><dir id='3EoXu'><q id='3EoXu'></q></dir></style></legend>
          • <tfoot id='3EoXu'></tfoot>
                  <tbody id='3EoXu'></tbody>

                <small id='3EoXu'></small><noframes id='3EoXu'>

                  本文介绍了如何获取 Swift 3.0 中按钮的当前标题,ios 使用 sender.titleForState(.Normal)!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图像下面这样快速获取 buttontitle.

                  I tried to get the title of a button in swift like below.

                  @IBAction func buttonAction(_ sender: Any) {
                    let buttonTitle = sender.titleForState(.Normal)!
                  }
                  

                  但它不起作用,甚至当我们在发送者之后按 . 时它没有给出任何 hint.

                  but it didn't work,even it doesn't give any hint when we press . after the sender.

                  那么在 swift 3.0 中这样做的正确方法是什么

                  so what is the correct way of doing this in swift 3.0

                  否则,如果我们创建一个 IBOutlet 然后我们使用它的 currentTitle,它可以正常工作,如下所示.为什么上面的 sender. 无法获取它

                  Or else if we create an IBOutlet and then we use its currentTitle, it works fine like below. Why we cannot get it with sender. for above

                  @IBOutlet var thebutton: UIButton!
                  
                  @IBAction func buttonAction(_ sender: Any) {
                    let buttonTitle = thebutton.currentTitle!
                    print(buttonTitle)
                  }
                  

                  推荐答案

                  因为参数 sender 的类型是 Any 而不是 UIButton.将方法签名更改为:

                  Because parameter sender is in type Any instead of UIButton. Change the method signature to:

                  @IBAction func buttonAction(_ sender: UIButton) {
                    if let buttonTitle = sender.title(for: .normal) {
                      print(buttonTitle)
                    }
                  }
                  

                  你应该很高兴.

                  这篇关于如何获取 Swift 3.0 中按钮的当前标题,ios 使用 sender.titleForState(.Normal)!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Push Notifications are delivered but didReceiveRemoteNotification is never called Swift(推送通知已交付,但 didReceiveRemoteNotification 从未被称为 Swift)
                  didReceiveRemoteNotification function doesn#39;t called with FCM notification server(不使用 FCM 通知服务器调用 didReceiveRemoteNotification 函数)
                  Firebase Cloud Messaging Cannot parse topic name(Firebase 云消息传递无法解析主题名称)
                  Creating Firebase topic for each user(为每个用户创建 Firebase 主题)
                  FCM Notification in iOS doesn#39;t play sound when received(iOS 中的 FCM 通知在收到时不播放声音)
                  Firebase API is not sending push notifications when using the API(使用 API 时 Firebase API 不发送推送通知)
                    <tbody id='LS5ao'></tbody>
                    1. <legend id='LS5ao'><style id='LS5ao'><dir id='LS5ao'><q id='LS5ao'></q></dir></style></legend>

                        <i id='LS5ao'><tr id='LS5ao'><dt id='LS5ao'><q id='LS5ao'><span id='LS5ao'><b id='LS5ao'><form id='LS5ao'><ins id='LS5ao'></ins><ul id='LS5ao'></ul><sub id='LS5ao'></sub></form><legend id='LS5ao'></legend><bdo id='LS5ao'><pre id='LS5ao'><center id='LS5ao'></center></pre></bdo></b><th id='LS5ao'></th></span></q></dt></tr></i><div id='LS5ao'><tfoot id='LS5ao'></tfoot><dl id='LS5ao'><fieldset id='LS5ao'></fieldset></dl></div>
                      1. <small id='LS5ao'></small><noframes id='LS5ao'>

                        • <tfoot id='LS5ao'></tfoot>
                            <bdo id='LS5ao'></bdo><ul id='LS5ao'></ul>