Hi I'm trying to pass data from two different classes and two different storyboards. I want to pass a UIimage
and UILabel
from sweetAndSalty4ViewController
to cartViewController
when the user clicks "sendData" button.
This is my code:
sweetAndSalty4ViewController
which I want to pass data from:
import UIKit
class sweetAndSalty4ViewController: UIViewController {
@IBOutlet var imageViewSweet: UIImageView!
@IBOutlet var labelsweet: UILabel!
@IBOutlet var sweeetTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func sendData(_ sender: UIButton) {
// I want to pass both labelSweet and imageViewSweet to cartViewController
}
}
And this is cartViewController
in which I want to display the UIimage
and the UILabel
:
import UIKit
class cartViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var cartItem = ""
@IBOutlet var cartTable: UITableView!
override func viewDidLoad() {
cartTable.delegate = self
cartTable.dataSource = self
// foodTable.separatorStyle = .none
view.backgroundColor = UIColor.init(red: 228/255, green: 230/255, blue: 234/255, alpha: 1)
navigationItem.title = "My Cart"
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cartItem.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
240
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cartCell") as! cartTableViewCell
cell.layer.cornerRadius = 30
cell.layer.borderWidth = 15.0
cell.layer.borderColor = UIColor.white.cgColor
cell.cartImage.layer.masksToBounds = true
cell.cartImage.layer.cornerRadius = 2
cell.cartImage.translatesAutoresizingMaskIntoConstraints = false
cell.cartImage.contentMode = .scaleAspectFill
cell.cartLabel.font = UIFont.systemFont(ofSize: 16, weight: .medium)
cell.cartLabel.textColor = .black
cell.cartLabel.translatesAutoresizingMaskIntoConstraints = false
cell.cartLabel.backgroundColor = .systemGray5
cell.cartLabel.text = ""
cell.cartImage.image = UIImage(named: "")
// cell.contentView.backgroundColor = .white
return cell
}
}
Please help me because I'm trying with it for weeks.