3.3. Send data back from Screen 2 to Screen 1
Updating the screens with new UI elements.
//
// ViewController.swift
//
import UIKit
class ViewController: UIViewController {
var textFieldMessage: UITextField!
var buttonSend: UIButton!
var labelMood: UILabel!
var imageMood: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//MARK: initializing the UI elements...
// code in between is omitted...
setupLabelMood()
setupImageMood()
//MARK: initializing the constraints...
initConstraints()
//MARK: on buttonSend tap...
buttonSend.addTarget(self, action: #selector(onButtonSendTapped),
for: .touchUpInside)
}
// code in between is omitted...
//labelMood...
func setupLabelMood(){
labelMood = UILabel()
labelMood.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(labelMood)
}
//imageMood...
func setupImageMood(){
imageMood = UIImageView()
imageMood.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(imageMood)
}
//updating constraints..
func initConstraints(){
NSLayoutConstraint.activate([
// textFieldMessage constraints...
textFieldMessage.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor),
textFieldMessage.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 32),
// buttonSend constraints...
buttonSend.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor),
buttonSend.topAnchor.constraint(equalTo: textFieldMessage.bottomAnchor, constant: 16),
// labelMood constraints...
labelMood.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor),
labelMood.topAnchor.constraint(equalTo: buttonSend.bottomAnchor, constant: 16),// labelMood constraints...
// imageMood constraints...
imageMood.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor),
imageMood.topAnchor.constraint(equalTo: labelMood.bottomAnchor, constant: 16),
])
}
}
Previous3.2. Send data from Screen 1 (ViewController) to Screen2 (ShowViewController)Next3.3.1. Send data back from Screen 2 to Screen 1: UIPickerView
Last updated