[英]MonthYearPickerView Library Swift 2.0 Issue
I'm using MonthYearPickerView Library in my project and it is running fine in Swift 1.2 now I'm trying to convert it into Swift 2.0 and I'm getting some issues. 我在我的项目中使用MonthYearPickerView库,它在Swift 1.2中运行良好,现在我试图将其转换为Swift 2.0,但遇到了一些问题。
I changed the calendar components into the code below under the commented code but I have an issue Cannot convert value of type 'NSDateComponents' to expected argument type 'Int'
when I'm trying to append or minus the value of the year. 我在注释代码下将日历组件更改为下面的代码,但是当我尝试添加或减去年份的值时, Cannot convert value of type 'NSDateComponents' to expected argument type 'Int'
。 So please how could I fix this issue? 所以,我该如何解决这个问题?
class MonthYearPickerView: UIPickerView, UIPickerViewDelegate, UIPickerViewDataSource { class MonthYearPickerView:UIPickerView,UIPickerViewDelegate,UIPickerViewDataSource {
override init(frame: CGRect) {
var years: [Int] = []
if years.count == 0 {
//var year = NSCalendar(identifier: NSCalendarIdentifierGregorian)!.component(.CalendarUnitYear, fromDate: NSDate())
let calendar = NSCalendar.currentCalendar()
var year = calendar.components(.Year, fromDate:NSDate())
for i in 1...10 {
years.append(year)
year++
}
}
self.years = years
super.init(frame: frame)
self.delegate = self
self.dataSource = self
//var month = NSCalendar(identifier: NSCalendarIdentifierGregorian)!.component(.CalendarUnitMonth, fromDate: NSDate())
let calendar = NSCalendar.currentCalendar()
let month = calendar.components(.Month, fromDate:NSDate())
self.selectRow(month-1, inComponent: 0, animated: false)
}
Use component
function not components
: var year = calendar.component(.Year, fromDate:NSDate())
使用component
函数而不是components
: var year = calendar.component(.Year, fromDate:NSDate())
or var year = calendar.components(.Year, fromDate:NSDate()).year
或var year = calendar.components(.Year, fromDate:NSDate()).year
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.