Swift - Pass data between views with custom controls

3

I'm doing a navigation between views and passing parameters through the segue.

The idea is this:

ViewA - You have a custom control (cell), with a label and an image. This custom cell has its own class called RateCell , which contains the @IBOutlet of its respective controls (Label and Image)

ViewB - It is a tableview view, where each cell has a Label and an image

The idea is that when you click on any cell in the ViewB, the data is passed to the custom ViewA cell, but I do not know how to access the custom control in ViewA, since it does not let me reference it with @IBOutlet because it is a Custom control.

How can I access the ViewA's custom control to insert the data into that control?

I'm starting with the development for swift.

    
asked by amelian 05.07.2016 в 13:34
source

2 answers

2

Hello, if there are two classes viewcontroller to pass data you use the segue, if it is from viewA to viewB with the use of segues and some global variables that receive the values you can achieve.

Example:

     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    if segue.identifier == "showViewB" {
        let destino = segue.destination as! viewB //ViewControllerB
        destino.imagen = imagen // variable del viewB que recibe lo que le envias de viewA
        destino.texto = texto // variable del viewB que recibe lo que le envias de viewA

    }

}

If it's from viewB to viewA you use the unwind segue, they work in almost the same way.

    @IBAction func mostrarViewA(segue : UIStoryboardSegue) {
    let viewController = segue.source as! viewB

    imagen = viewController.imagen //variable de viewA que recibe los datos de viewB
    texto = viewController.text //variable de viewA que recibe los datos de viewB
    tablewView.reloadData()



}
    
answered by 10.03.2017 в 00:52
0

If you want to pass data to another class, create two variables in the view A calls image and title for example I either use the didSet to control when these values change and reload the table, or directly pass the data to this variable through segue and when you enter Class A you reload the table.

    
answered by 20.09.2016 в 15:29