Cannot assign a value of type ViewController to a value of type 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

to

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate

Leave a Comment