有人会介意帮我完成我的这个小项目吗?对于那些密切关注我在这里提出的问题的人,我在调整嵌套数组所需的代码时遇到了问题,而我的项目就在于此。
为了防止我的代码看起来奇怪/不熟悉,我的项目基于Jared Davidson的本教程,这是该项目的youtube链接。
这是我的项目(它在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]
在最后,我有点迷失了。真的很感激任何帮助!
答案 0 :(得分:1)
您的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]
}