我一直在网上挖掘,到目前为止,我已经看到了文本字段的IBAction示例,各种方式关于完成按钮的工作原理(大多数没有完成按钮),但我想知道我是否可以从我的代码中回收或基于下面的下拉菜单:
let wellheadPresstest : [String] = ["PSIG","MPAG"]var wellboreStatusPickerVIEw = UIPickerVIEw()overrIDe func vIEwDIDLoad() { let wellboreStatusToolbar = UIToolbar() let spacebutton = UIbarbuttonItem(barbuttonSystemItem: UIbarbuttonSystemItem.FlexibleSpace,target: nil,action: nil) let donebuttonWellbore = UIbarbuttonItem(Title: "Done",style: UIbarbuttonItemStyle.Plain,target: self,action: "donePickerWellbore") wellboreStatusToolbar.barStyle = UIbarStyle.Default wellboreStatusToolbar.translucent = true wellboreStatusToolbar.tintcolor = UIcolor(red: 76/255,green: 217/255,blue: 100/255,Alpha: 1) wellboreStatusToolbar.sizetoFit() wellboreStatusToolbar.setItems([spacebutton,spacebutton,donebuttonWellbore],animated: false) wellboreStatusToolbar.userInteractionEnabled = true wellboreStatusPickerVIEw.delegate = self self.samplingWaterFormOneVIEw.textfIElDWellbore.inputVIEw = wellboreStatusPickerVIEw self.samplingWaterFormOneVIEw.textfIElDWellbore.inputAccessoryVIEw = wellboreStatusToolbar}// VarIoUs required PickerVIEw functionsfunc donePickerWellbore(){ let row = wellboreStatusPickerVIEw.selectedRowInComponent(0); pickerVIEw(wellboreStatusPickerVIEw,dIDSelectRow: row,inComponent:0) self.samplingWaterFormOneVIEw.textfIElDWellbore.resignFirstResponder()}
这是我试过的:
var dateSampledPickerVIEw = UIDatePicker()overrIDe func vIEwDIDLoad() { let dateSampledPickerToolbar = UIToolbar() let donebuttonDate = UIbarbuttonItem(Title: "Done",action: "donePickerDate") dateSampledPickerToolbar.barStyle = UIbarStyle.Default dateSampledPickerToolbar.translucent = true dateSampledPickerToolbar.tintcolor = UIcolor(red: 76/255,Alpha: 1) dateSampledPickerToolbar.sizetoFit() dateSampledPickerToolbar.setItems([spacebutton,donebuttonDate],animated: false) dateSampledPickerToolbar.userInteractionEnabled = true dateSampledPickerVIEw.datePickerMode = UIDatePickerMode.Date dateSampledPickerVIEw.addTarget(self,action: Selector("datePickerValueChanged"),forControlEvents: UIControlEvents.ValueChanged) self.samplingWaterFormOneVIEw.textfIEldDateSampled.inputVIEw = dateSampledPickerVIEw self.samplingWaterFormOneVIEw.textfIEldDateSampled.inputAccessoryVIEw = dateSampledPickerToolbar self.samplingWaterFormOneVIEw.textfIEldDateSampled.delegate = self}func datePickerValueChanged(sender:UIDatePicker) { let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = "YYYY-MM-DD" dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle self.samplingWaterFormOneVIEw.textfIEldDateSampled.text = dateFormatter.stringFromDate(sender.date)}func donePickerDate(){ self.samplingWaterFormOneVIEw.textfIEldDateSampled.resignFirstResponder()}
上面的代码确实显示了一个带有日期选择器的d出菜单,当我在文本字段顶部时,带有完成按钮,但文本字段没有获取日期.
编辑:还尝试修改datePickerValueChanged,使其没有发件人,并使用dateSampledPickerVIEw作为文本字段.没工作.
在函数中添加注释表明没有调用datePickerValueChanged函数.
我究竟做错了什么?
解决方法 我相信datePickerValueChanged函数没有被调用,因为你还没有设置dateSampledPickerVIEw的委托.所以简单地输入
dateSampledPickerVIEw.delegate = self
*********编辑****************
好吧,仔细观察后我相信你已经错误地设置了动作调用.替换此行
dateSampledPickerVIEw.addTarget(self,forControlEvents: UIControlEvents.ValueChanged)
同
dateSampledPickerVIEw.addTarget(self,action: "datePickerValueChanged",forControlEvents: UIControlEvents.ValueChanged)
删除选择器()
总结以上是内存溢出为你收集整理的ios – Swift:带有完成按钮的文本框上的d出DatePicker全部内容,希望文章能够帮你解决ios – Swift:带有完成按钮的文本框上的d出DatePicker所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)