dimanche 20 octobre 2019

Should the button target method logic be defined in UIView or UIViewController

I have a button and a textview defined in a UIView Class. Which will make a networks request when pressed. Should i add the button.addTarget in UIView or UIViewController. what is the MVC way to do it.

class MessageInputView: UIView {

    let send_button: UIButton = {
        let button = UIButton()
        button.translatesAutoresizingMaskIntoConstraints = false
        button.backgroundColor = .red
        button.setTitle("Send", for: .normal)
        button.setTitleColor(UIColor.black, for: .normal)
        return button
    }()

    let textView: UITextView = {
        let textView = UITextView()
        textView.translatesAutoresizingMaskIntoConstraints=false
        textView.clipsToBounds = true
        textView.layer.cornerRadius = 19.5
        textView.layer.borderWidth = 1
        textView.layer.borderColor = UIColor.inputTextViewColor.cgColor
        return textView
    }()

}

class ChatMessagesViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {



    let messageInputView = MessageInputView()


    override func viewDidLoad() {
        super.viewDidLoad()


        self.view.backgroundColor = .white
        messageInputView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(messageInputView)
        setMessagesInputViewConstraints()
    }

}

Aucun commentaire:

Enregistrer un commentaire