destinationVC 和成员类型的问题

Issue with destinationVC and member types

有人介意帮我完成我的这个小项目吗?对于那些密切关注我在这里提出的问题的人来说,我在调整嵌套数组所需的代码时遇到了问题,而我的项目恰恰就在于此。

以防万一我的代码看起来 odd/unfamiliar,我的项目基于 Jared Davidson 的教程,这里是该项目的 youtube link。

https://www.youtube.com/watch?v=pR6dR-vVZeY

这是我的项目(在 Dropbox 上),

https://www.dropbox.com/sh/u9rkvwsrcdoa7q8/AABwKm_djSB2oENzuJNT1u35a?dl=0

我的 prepareforsegue 函数和这段代码确实有问题。

 var indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!
 var DestViewController = segue.destinationViewController as! RestaurantNameTable

 var selectedRestaurants : [Restaurant]

 selectedRestaurants = restaurantNamesArray[indexPath.section]

 DestViewController.restaurantNamesArray = selectedRestaurants

基本上,我的 restaurantNamesTable 没有名为 restaurantNamesArray 的成员。 或者我的代码应该如下...

DestViewController.selectedRestaurants =restaurantNamesArray[indexPath.section]    

?

我在最后有点失落。任何帮助将不胜感激!

您的 RestaurantNameTable 有一个名为 selectedRestaurants 的 属性 但没有一个名为 restaurantNamesArray,因此您在尝试写入时遇到错误。

你想要

var indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!
var DestViewController = segue.destinationViewController as! RestaurantNameTable
var selectedRestaurants : [Restaurant]
selectedRestaurants = restaurantNamesArray[indexPath.section]

DestViewController.selectedRestaurants = selectedRestaurants

或更安全简洁

if let destViewController = segue.destinationViewController as? RestaurantNameTable {
    let indexPath = self.tableView.indexPathForSelectedRow!
    destViewController.selectedRestaurants = restaurantNamesArray[indexPath.section]
}