尝试用JSon数据重新加载FSCalendar,但崩溃 [英] Trying to Reload FSCalendar with JSon data but it crashes
问题描述
此问题与我以前的帐户的问题相关联.
this question is linked with the my previous account's question.
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()
}
}
我在此处附加了错误日志,请提前帮助.
I'm attaching the error log here please help thanks in advance.
错误日志
2017-06-17 10:23:50.671 ezSchool [1848:24475] -[UICachedDeviceWhiteColor unsignedLongLongValue]:无法识别的选择器已发送到实例0x608000059ec0 2017-06-17 10:23:50.672 ezSchool [1848:24475]无法设置( placeholderType )用户定义 在(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
2017-06-17 10:23:50.671 ezSchool[1848:24475] -[UICachedDeviceWhiteColor unsignedLongLongValue]: unrecognized selector sent to instance 0x608000059ec0 2017-06-17 10:23:50.672 ezSchool[1848:24475] Failed to set (placeholderType) user defined inspected property on (FSCalendar): -[UICachedDeviceWhiteColor unsignedLongLongValue]: unrecognized selector sent to instance 0x608000059ec0 2017-06-17 10:23:50.672 ezSchool[1848:24475] -[UICachedDeviceWhiteColor unsignedLongLongValue]: unrecognized selector sent to instance 0x608000059ec0 2017-06-17 10:23:50.672 ezSchool[1848:24475] Failed to set (firstWeekday) user defined inspected property on (FSCalendar): -[UICachedDeviceWhiteColor unsignedLongLongValue]: unrecognized selector sent to instance 0x608000059ec0 2017-06-17 10:23:50.672 ezSchool[1848:24475] -[UICachedDeviceWhiteColor doubleValue]: unrecognized selector sent to instance 0x608000059ec0 2017-06-17 10:23:50.673 ezSchool[1848:24475] Failed to set (headerHeight) user defined inspected property on (FSCalendar): -[UICachedDeviceWhiteColor doubleValue]: unrecognized selector sent to instance 0x608000059ec0 2017-06-17 10:23:50.673 ezSchool[1848:24475] -[UICachedDeviceWhiteColor doubleValue]: unrecognized selector sent to instance 0x608000059ec0 2017-06-17 10:23:50.673 ezSchool[1848:24475] Failed to set (headerTitleTextSize) user defined inspected property on (FSCalendar): -[UICachedDeviceWhiteColor doubleValue]: unrecognized selector sent to instance 0x608000059ec0
推荐答案
将功能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()
}
请查看下面所附的图像是否是所需的输出
Please see whether the below attached image is your desired output
这篇关于尝试用JSon数据重新加载FSCalendar,但崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!