Passing integer with Segue

Axel Mårtensson

I have a problem when trying to send data to a new viewController. This line executes

destination1.path = path

Because I get the path to the new ViewController, seems be some problem with integers.

I get this error message:

2017-05-26 20:37:14.442509+0200 Subscription[1224:301622] UIView: 0x105d294f0; frame = (0 0; 414 736); autoresize = W+H; layer = CALayer: 0x17403f360>>'s window is not equal to Subscription.ViewController2: 0x105d3fcb0>'s view's window!

// method to run when table view cell is tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print("You tapped cell number \(indexPath.row).")

    let index = indexPath.row
    performSegue(withIdentifier: "EditSegue1", sender: index)


}
@IBAction func backButton(_ sender: Any) {
     self.dismiss(animated: true, completion: nil)
}

// Prepare for next view.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if let destination1 = segue.destination as? ViewController2 {

        destination1.path = path

        if let index = sender as? Int {
            destination1.index = index
        }
    }
}

My second viewController.

var path = ""
var index = 0


override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    print(path)
    print(index)
}
Jake T.

A few issues here: Sender should be an object triggering an event. In most cases, but not all, it should be self.

The second is that you don't have a check for your segue identifier. Everything inside of your prepareForSegue call should be wrapped inside an if( segue.identifier == )` block.

Third, path doesn't appear to be declared in the function you showed, so unless it appears elsewhere, that may cause unintended behavior.

Fourth, since you're trying to use the sender as an int, it's throwing things off. I assume you have a property for path declared. You should probably also declare one for index, and pass that instead of trying to use sender. You also then don't have to wrap it in the type check.

You may also see an issue since you don't declare the types of path and index on your second view controller. You may need to, in order for the first view controller to know what types are allowed to be assigned.

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 UIImage with segue

From

Passing data with unwind segue

From Dev

Passing String through Segue

From Dev

Passing data with segue in the tableViewCell

From Dev

String not passing through segue?

From Dev

Passing data with segue

From Dev

Passing object through segue

From Dev

Passing String Segue Swift

From Dev

Passing data through Segue

From Dev

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

From Dev

Passing data with segue through TabBarControllerController

From Dev

Passing data with segue through navigationController

From Dev

objectAtIndex not passing selected row in segue

From Dev

Swift: Prepare for segue not passing data

From Dev

Passing data between storyboards with no segue

From Java

Passing an integer by reference in Python

From Dev

Passing PHP integer to JavaScript

From Dev

Passing data between View Controllers using Segue

From Dev

Passing Data between View Controllers without segue

From Dev

Swift one out of three segue is not passing data

From Dev

iOS Segue not working as expected when passing value

From Dev

Passing data with segue from UITableView to UIViewController

From Dev

Passing data from modal segue to parent

From Dev

Passing custom data with map pin segue

From Dev

Passing data on segue to view controller (Swift)

From Dev

How to get json data for passing it by segue

From Dev

Passing data to new ViewController through Segue

From Dev

Passing CLLocation to the next view using segue

From Dev

Passing documentID of Firestore using segue in Swift