destinationVC和成员类型的问题

时间:2015-10-22 03:18:52

标签: ios arrays swift uistoryboardsegue

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

为了防止我的代码看起来奇怪/不熟悉,我的项目基于Jared Davidson的本教程,这是该项目的youtube链接。

  

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]    

在最后,我有点迷失了。真的很感激任何帮助!

enter image description here

1 个答案:

答案 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]
}