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
Value of type 'UIViewController' has no member 'varView'
提问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 YourViewController
and 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 varView
member available in that class
并确保varView
该类中有可用的成员
Hope this will help :)
希望这会有所帮助:)