• <legend id='i8SOA'><style id='i8SOA'><dir id='i8SOA'><q id='i8SOA'></q></dir></style></legend>

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

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

        • <bdo id='i8SOA'></bdo><ul id='i8SOA'></ul>

        无法将 ViewController 类型的值分配给 UITextFieldDelegate 类型的值?

        时间:2023-07-28
            <i id='ZqU2S'><tr id='ZqU2S'><dt id='ZqU2S'><q id='ZqU2S'><span id='ZqU2S'><b id='ZqU2S'><form id='ZqU2S'><ins id='ZqU2S'></ins><ul id='ZqU2S'></ul><sub id='ZqU2S'></sub></form><legend id='ZqU2S'></legend><bdo id='ZqU2S'><pre id='ZqU2S'><center id='ZqU2S'></center></pre></bdo></b><th id='ZqU2S'></th></span></q></dt></tr></i><div id='ZqU2S'><tfoot id='ZqU2S'></tfoot><dl id='ZqU2S'><fieldset id='ZqU2S'></fieldset></dl></div>

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

              <tbody id='ZqU2S'></tbody>
              <legend id='ZqU2S'><style id='ZqU2S'><dir id='ZqU2S'><q id='ZqU2S'></q></dir></style></legend>
              <tfoot id='ZqU2S'></tfoot>

                • <bdo id='ZqU2S'></bdo><ul id='ZqU2S'></ul>
                  本文介绍了无法将 ViewController 类型的值分配给 UITextFieldDelegate 类型的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我写 self.MessageTextField.delegate = self 行时的错误:

                  Here's the error when I wrote the line self.MessageTextField.delegate = self:

                  /ChatApp/ViewController.swift:27:42: 无法将ViewController"类型的值分配给UITextFieldDelegate"类型的值?

                  /ChatApp/ViewController.swift:27:42: Cannot assign a value of type 'ViewController' to a value of type 'UITextFieldDelegate?'

                  这是我的 Swift 代码 (ViewerController.swift):

                  Here's my Swift code (ViewerController.swift):

                  //
                  //  ViewController.swift
                  //  ChatApp
                  //
                  //  Created by David Chen on 15/4/12.
                  //  Copyright (c) 2015年 cwsoft. All rights reserved.
                  //
                  
                  import UIKit
                  import Parse
                  
                  class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
                  
                      var messagesArray:[String] = [String]()
                  
                      @IBOutlet weak var MessageTableView: UITableView!
                      @IBOutlet weak var ButtonSend: UIButton!
                      @IBOutlet weak var DockViewHeightConstraint: NSLayoutConstraint!
                      @IBOutlet weak var MessageTextField: UITextField!
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          //
                          self.MessageTableView.delegate = self
                          self.MessageTableView.dataSource = self
                          //Set delegate
                          self.MessageTextField.delegate = self
                  
                          self.messagesArray.append("Test 1")
                          self.messagesArray.append("Test 2")
                          self.messagesArray.append("Test 3")
                      }
                  
                      @IBAction func ButtonSendPressed(sender: UIButton) {
                          self.view.layoutIfNeeded()
                          UIView.animateWithDuration(0.5, animations: {
                              self.DockViewHeightConstraint.constant = 400
                              self.view.layoutIfNeeded()
                              }, completion: nil)
                      }
                  
                      //MARK : TextField Delegage Methods
                  
                  
                      //MARK : Table View Delegate Methods
                  
                      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
                          let cell = self.MessageTableView.dequeueReusableCellWithIdentifier("MessageCell") as! UITableViewCell
                          cell.textLabel?.text = self.messagesArray[indexPath.row]
                          return cell
                      }
                  
                      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                          return messagesArray.count
                      }
                  }
                  

                  推荐答案

                  self.MessageTextField.delegate = self 导致错误,因为您尝试将 self 分配为UITextFielddelegate.
                  但是您的 ViewController 不是 UITextFieldDelegate.要使您的课程成为这种委托,您需要采用 UITextFieldDelegate 协议.这可以通过将其添加到您的类继承/符合的协议和类列表中来实现.在您的情况下,这是通过更改行来完成的

                  The line self.MessageTextField.delegate = self causes the error since you try to assign self as the delegate of a UITextField.
                  But your ViewController is not a UITextFieldDelegate. To make your class this kind of delegte, you need to adopt the UITextFieldDelegate protocol. This can be achieved by adding it to the list of protocols and classes your class inherits from / conforms to. In your case that is done by changing the line

                  class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
                  

                  class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate
                  

                  这篇关于无法将 ViewController 类型的值分配给 UITextFieldDelegate 类型的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:代表们,我无法理解他们 下一篇:试图理解 Swift 中的协议/委托

                  相关文章

                      • <bdo id='FXkDj'></bdo><ul id='FXkDj'></ul>

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

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