String not passing through segue?

diligentcrush

I'm trying to build a cell that can be tapped, store the current text of the cell label, and send that label to a different view controller. I've looked everywhere and can't figure out why it's not passing

View controller with table view

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "openWave" {
        if let destVC = segue.destination as? GoToWaveViewController {
            destVC.waveLabel = sender as! String
            print("sdf: \(sender)")
        }
    }
} ...

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let cell = self.tableView.cellForRow(at: indexPath) as! MyWavesTableViewCell
    let text = cell.waveLabel.text!
    let label = self.groupNames[indexPath.row]
    print(label)
    performSegue(withIdentifier: "openWave", sender: label)
    //self.tableView.deselectRow(at: indexPath, animated: true)}

Second View Controller

class GoToWaveViewController: UIViewController {

@IBOutlet weak var waveName: UILabel!
var waveLabel: String!

override func viewDidLoad() {
    super.viewDidLoad()

}

override func viewWillAppear(_ animated: Bool) {
    setProperties()
}

func setProperties() {
    self.waveLabel = self.waveName.text!
    print("asdf: \(waveLabel)")
    print("asdfa: \(self.waveLabel)")
}
Sh_Khan

I see it's a logical error you may need

self.waveName.text =  self.waveLabel

Instead of

self.waveLabel = self.waveName.text!

And that overwrites the sended value , so this

print("asdf: \(waveLabel)")
print("asdfa: \(self.waveLabel)")

will print empty values

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing String through Segue

From Dev

Passing object through segue

From Dev

Passing data through Segue

From Dev

xcode 6 - swift - passing a string through popover segue

From Dev

Passing String Segue Swift

From Dev

Passing data with segue through TabBarControllerController

From Dev

Passing data with segue through navigationController

From Dev

Passing data to new ViewController through Segue

From Dev

iOS Delegates instead of passing data through a segue

From Dev

Passing a string variable through ajax

From Dev

Error when passing string through

From Dev

Passing a string to second view controller's UILabel when performing segue

From Dev

Data passing through intents with string returns null

From Dev

Passing a string through 2 modal segues

From Dev

Passing query string through variable value fails

From Dev

Passing string through multiple filters for matching

From Dev

Empty string after passing through the function

From Dev

Passing string variable through function in python 3.7.6

From Dev

Passing a query string through redirect for maintenance mode

From Dev

Javascript passing through formatted int as string to function

From Dev

Passing UIImage with segue

From

Passing data with unwind segue

From Dev

Passing data with segue in the tableViewCell

From Dev

Passing data with segue

From Dev

Passing integer with Segue

From Dev

Swift4 Xcode9 Passing variable between ViewControllers through segue

From Dev

Passing data through a segue from a detailDisclosure button in a map callout to a new DetailView

From Dev

Passing an NSArray to a segue, which passes it to another segue?

From

Pass data through segue

Related Related

HotTag

Archive