TableViewController
에 다음과 같은 segue가 있으며 각 테이블 행에는 Fruit 객체가 있습니다. 각 행의 객체를 행의 객체에 대한 자세한 정보를 표시하는보기 제어기에 전달하려고합니다. 그래서 View Controller 전체에서 Fruit 객체를 전송하기 위해 아래의 segue를 작성했습니다. FruitDescriptionViewController
에서스토리 보드를 통해 객체 전달하기
, 나는 그것이 나를 변수 var chosenFruit = Fruit
을 정의하고 SEGUE에, 나는 오류가 발생하지 않기 때문에 행에서 개체에 대해 수행 할 변수를 정의하는 방법을 알아낼 수 없었다 cannot pass type Fruit to type Fruit.type
과일 개체를 segue를 통해 전달하고 과일 변수 FruitDescriptionViewController
에 저장하는 방법은 무엇입니까?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "FruitDetails" {
if let indexPath = tableView.indexPathForSelectedRow {
var fruit = fruits[indexPath.row]
let controller = segue.destination as? FruitDescriptionViewController
controller?.chosenFruit = Fruit(name: fruit.name, url: fruit.url, fruitArray: fruit.fruitArray)
}
}
}
'var selectedFruit = 과일'은 'var selectedFruit : 과일'이어야합니다. – Callam