这个问题与我以前的帐户问题有关。
码
import UIKit
import FSCalendar
class AttendenceViewController : UIViewController, FSCalendarDelegate, FSCalendarDataSource, FSCalendarDelegateAppearance
{
@IBOutlet weak var calendar: FSCalendar!
var presentdays : Array = [String]()
var absentdays : Array = [String]()
fileprivate let gregorian: Calendar = Calendar(identifier: .gregorian)
fileprivate lazy var dateFormatter1: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
return formatter
}()
fileprivate lazy var dateFormatter2: DateFormatter = {
let formatter2 = DateFormatter()
formatter2.dateFormat = "dd"
return formatter2
}()
override func viewDidLoad() {
super.viewDidLoad()
self.getdateFromJSON()
}
func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, fillDefaultColorFor date: Date) -> UIColor? {
let datestring2 : String = dateFormatter1.string(from: date)
if presentdays.contains(datestring2)
{
return UIColor.green
}
else if absentdays.contains(datestring2)
{
return UIColor.red
}
else
{
return nil
}
}
func getdateFromJSON()
{
let url = NSURL(string: "ezschoolportalapi.azurewebsites.net/api/Student/AttendanceDetails?schoolid=1&studentid=2&month=6&year=2017")
let request = NSMutableURLRequest(url: url! as URL)
let task = URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error)
in
guard error == nil && data != nil else
{
print("Error:",error)
return
}
let httpstatus = response as? HTTPURLResponse
if httpstatus?.statusCode == 200
{
if data?.count != 0
{
if let responseJSON = (try? JSONSerialization.jsonObject(with: data!, options: .allowFragments)) as? [String:Any],
let presentdetails = responseJSON["Present"] as? [[String:Any]],
let Absentdetails = responseJSON["Absent"] as? [[String:Any]] {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
self.presentdays = presentdetails.flatMap { dateFormatter.date(from: $0["Date"] as! String) }.flatMap {
self.dateFormatter2.string(from:$0)
}
self.absentdays = Absentdetails.flatMap { dateFormatter.date(from: $0["Date"] as! String) }.flatMap { self.dateFormatter2.string(from:$0) }
DispatchQueue.main.async
{
self.calendar.reloadData()
}
}
}
else
{
print("No data got from URL")
}
}
else{
print("error httpstatus code is :",httpstatus?.statusCode)
}
}
task.resume()
}
}
我在这里附上错误日志,请提前帮助。
错误日志
2017-06-17 10:23:50.671 ezSchool [1848:24475] - [UICachedDeviceWhiteColor unsignedLongLongValue]:无法识别的选择器发送到实例0x608000059ec0 2017-06-17 10:23:50.672 ezSchool [1848:24475]无法设置(占位符类型)用户定义 检查属性(FSCalendar): - [UICachedDeviceWhiteColor unsignedLongLongValue]:发送到实例的无法识别的选择器 0x608000059ec0 2017-06-17 10:23:50.672 ezSchool [1848:24475] - [UICachedDeviceWhiteColor unsignedLongLongValue]:无法识别的选择器发送到实例0x608000059ec0 2017-06-17 10:23:50.672 ezSchool [1848:24475]无法设置( firstWeekday )用户定义 检查属性(FSCalendar): - [UICachedDeviceWhiteColor unsignedLongLongValue]:发送到实例的无法识别的选择器 0x608000059ec0 2017-06-17 10:23:50.672 ezSchool [1848:24475] - [UICachedDeviceWhiteColor doubleValue]:无法识别的选择器发送到实例0x608000059ec0 2017-06-17 10:23:50.673 ezSchool [1848:24475] 无法设置( headerHeight )用户定义的检查属性 (FSCalendar): - [UICachedDeviceWhiteColor doubleValue]:无法识别 选择器发送到实例0x608000059ec0 2017-06-17 10:23:50.673 ezSchool [1848:24475] - [UICachedDeviceWhiteColor doubleValue]: 无法识别的选择器发送到实例0x608000059ec0 2017-06-17 10:23:50.673 ezSchool [1848:24475]设置失败( headerTitleTextSize ) 用户定义的检查属性(FSCalendar): - [UICachedDeviceWhiteColor doubleValue]:无法识别的选择器发送到实例0x608000059ec0
答案 0 :(得分:0)
将函数getdateFromJSON()
替换为
func getdateFromJSON()
{
let url = NSURL(string: "http://ezschoolportalapi.azurewebsites.net/api/Student/AttendanceDetails?schoolid=1&studentid=2&month=6&year=2017")
let request = NSMutableURLRequest(url: url! as URL)
let task = URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error)
in
guard error == nil && data != nil else
{
print("Error:",error ?? "error")
return
}
let httpstatus = response as? HTTPURLResponse
if httpstatus?.statusCode == 200
{
if data?.count != 0
{
if let responseJSON = (try? JSONSerialization.jsonObject(with: data!, options: .allowFragments)) as? [String:Any],
let presentdetails = responseJSON["Present"] as? [[String:Any]],
let Absentdetails = responseJSON["Absent"] as? [[String:Any]] {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
self.presentdays = presentdetails.flatMap { dateFormatter.date(from: $0["Date"] as! String) }.flatMap {
self.dateFormatter1.string(from:$0)
}
self.absentdays = Absentdetails.flatMap { dateFormatter.date(from: $0["Date"] as! String) }.flatMap { self.dateFormatter1.string(from:$0) }
DispatchQueue.main.async
{
self.calendar.reloadData()
}
}
}
else
{
print("No data got from URL")
}
}
else{
print("error httpstatus code is :",httpstatus?.statusCode ?? "5")
}
}
task.resume()
}