Свифт один из трех segue не передает данные - PullRequest
0 голосов
/ 16 января 2019

Я пытаюсь передать данные другому контроллеру с помощью перехода после нажатия на кнопку.

Это мой код:

@IBAction func agilityDogBtnPressed(_ sender: Any) {
    if let objs = controller.fetchedObjects, objs.count > 0 {
        let course = objs[0]
            self.performSegue(withIdentifier: "DogAgilitySegue", sender: course)
    }
}
@IBAction func baseEducationBtnPressed(_ sender: Any) {
    if let objs = controller.fetchedObjects, objs.count > 0 {
        let course = objs[1]
        self.performSegue(withIdentifier: "BaseEducationSegue", sender: course)
    }
}
@IBAction func puppyBtnPressed(_ sender: Any) {
    if let objs = controller.fetchedObjects, objs.count > 0 {
        let course = objs[2]
        self.performSegue(withIdentifier: "PuppyClassSegue", sender: course)
    }
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "DogAgilitySegue" {
        if let destination = segue.destination as? ClassDetailsVC {
            if let course = sender as? Course {
                destination.course = course
            }
        }
    } else if segue.identifier == "PuppyClassSegue" {
        if let destination = segue.destination as? ClassDetailsVC {
            if let course = sender as? Course {
                destination.course = course
            }
        }
    } else if segue.identifier == "BaseEducationSegue" {
        if let destination = segue.destination as? ClassDetailsVC {
            if let course = sender as? Course {
                destination.course = course
            }
        }
    }

Моя проблема в том, что первые два сега работают отлично. Третий (PuppyClassSegue) не передает данные. Он открывает страницу, но данные не отображаются, в основном destination.course не происходит.

Есть идеи, как это возможно?

Спасибо!

enter image description here

1 Ответ

0 голосов
/ 16 января 2019

Похоже, что курс nil, вы также можете сделать это, подключив все кнопки к одному действию и установив для них теги 0,1,2 соответственно

@IBAction func agilityDogBtnPressed(_ sender: UIButton) {
    if let objs = controller.fetchedObjects, objs.count > 0 {
        let course = objs[sender.tag]
            self.performSegue(withIdentifier: "SegueFromCon", sender: course)
} 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
        if let destination = segue.destination as? ClassDetailsVC {
            if let course = sender as? Course {
                print("hit here ",course)
                destination.course = course
            }
        }
}

сделать 1 переход с именем скажем SegueFromCon из текущего виртуального канала в подробности VC

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...