到目前为止,我已经将UIPickerVIEwDelegate添加到我的类中,如下所示:
class ExampleClass: UIVIEwController,UIPickerVIEwDelegate
我还创建了我的UIPickerVIEw并为其设置了委托:
@IBOutlet var year: UIPickerVIEwyear.delegate = self
现在我无法将以下内容转换为Swift代码:
- (NSInteger)numberOfComponentsInPickerVIEw:(UIPickerVIEw *)pickerVIEw
任何帮助,将不胜感激
解决方法 这实际上是UIPickerVIEwDataSource协议中的一个方法,因此您还需要确保设置选择器视图的dataSource属性:year.dataSource = self. Swift本地方式似乎是在类扩展中实现协议,如下所示:class ExampleClass: UIVIEwController { // propertIEs and methods,etc.}extension ExampleClass: UIPickerVIEwDataSource { // two required methods func numberOfComponentsInPickerVIEw(pickerVIEw: UIPickerVIEw!) -> Int { return 1 } func pickerVIEw(pickerVIEw: UIPickerVIEw!,numberOfRowsInComponent component: Int) -> Int { return 5 }}extension ExampleClass: UIPickerVIEwDelegate { // several optional methods: // func pickerVIEw(pickerVIEw: UIPickerVIEw!,wIDthForComponent component: Int) -> CGfloat // func pickerVIEw(pickerVIEw: UIPickerVIEw!,rowHeightForComponent component: Int) -> CGfloat // func pickerVIEw(pickerVIEw: UIPickerVIEw!,TitleForRow row: Int,forComponent component: Int) -> String! // func pickerVIEw(pickerVIEw: UIPickerVIEw!,attributedTitleForRow row: Int,forComponent component: Int) -> NSAttributedString! // func pickerVIEw(pickerVIEw: UIPickerVIEw!,vIEwForRow row: Int,forComponent component: Int,reusingVIEw vIEw: UIVIEw!) -> UIVIEw! // func pickerVIEw(pickerVIEw: UIPickerVIEw!,dIDSelectRow row: Int,inComponent component: Int)}总结
以上是内存溢出为你收集整理的ios – 在Swift中为UIPickerView委派方法全部内容,希望文章能够帮你解决ios – 在Swift中为UIPickerView委派方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)