输入“myViewController”不符合Swift中的协议UIPIckerDataSource [英] Type "myViewController" does not conform to protocol UIPIckerDataSource in Swift
问题描述
我只是在Swift中创建一个新类,它叫做 myViewController
,它是一个 UIViewController
。
现在我正在尝试将其设为UIPickerViewDelegate和DataSource,但我收到了一个奇怪的错误
I just create a new class in Swift, it's called myViewController
and it's a UIViewController
.
Now I'm trying to make it a UIPickerViewDelegate and DataSource but i got a strange error
import UIKit
class myViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
...
}
它说类型myViewController不符合UIPickerViewDataSource上的协议UIPIckerDataSource
。
这是Xcode-Beta 3的错误吗?
推荐答案
您需要实现 UIPickerViewDataSource
和 UIPickerViewDelegate
,如果你想要符合这些协议。
You need to implement all the required methods of UIPickerViewDataSource
and UIPickerViewDelegate
, if you want to conform to these protocols.
Swift在协议方面更像java,因为如果你没有实现协议声明的所有必需方法,你将得到编译时错误而不是运行时异常。
Swift is more like java when it comes to protocols because if you don't implement all the required methods declared by a protocol you are going to get a compile time error instead of a run time exception.
这篇关于输入“myViewController”不符合Swift中的协议UIPIckerDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!