类型的价值' UIViewController'没有会员' varView'

时间:2016-05-03 12:21:40

标签: ios xcode swift uiviewcontroller xcode7.3

请快速帮助

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    var DestVC = segue.destinationViewController as UIViewController

    var indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!

    DestVC.varView = indexPath.row // This is the error line

}

错误是

  

类型的价值' UIViewController'没有会员' varView'

2 个答案:

答案 0 :(得分:3)

使用目标视图控制器更改UIViewController。 例如,您的destinationviewcontroller名称为YourViewController 并且如果让安全打开

也使用
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let DestVC = segue.destinationViewController as? YouViewController  {

var indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!

DestVC.varView = indexPath.row 

}

答案 1 :(得分:2)

替换

var DestVC = segue.destinationViewController as UIViewController

var DestVC = segue.destinationViewController as YourDestinationClassName

并确保该班级中有varView个成员

希望这会有所帮助:)

相关问题