xcode “UIViewController”类型的值没有成员“varView”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37004012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:47:16  来源:igfitidea点击:

Value of type 'UIViewController' has no member 'varView'

iosxcodeswiftuiviewcontrollerxcode7.3

提问by Jeylani Osman

Please help fast

请快点帮忙

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

}

The error is

错误是

Value of type 'UIViewController' has no member 'varView'

“UIViewController”类型的值没有成员“varView”

回答by Sahil

change UIViewController with your destination view controller. for e.g your destinationviewcontroller name is YourViewControllerand also use if let for safely unwrap

使用目标视图控制器更改 UIViewController。例如,您的目的地YourViewController视图控制器名称是并且还使用 if let 安全解包

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

var indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!

DestVC.varView = indexPath.row 

}

回答by Ketan Parmar

replace

代替

var DestVC = segue.destinationViewController as UIViewController

with

var DestVC = segue.destinationViewController as YourDestinationClassName

and make sure that there is a varViewmember available in that class

并确保varView该类中有可用的成员

Hope this will help :)

希望这会有所帮助:)