Reputation: 13
I am using calender with events it's working fine, all the events coming from JSON I can parse the JSON data stored in to array, if I can show the JSON Array its showing empty After scrolling the calender JSON Array showing the data, this is the code
var EventsData = [Event]()
override func viewDidLoad() {
super.viewDidLoad()
getdairyDetails()
}
inside the getdairyDetails()
if errorCode == "0" {
if let event_list = jsonData["events"] as? NSArray {
self.EventDates.removeAll()
for i in 0 ..< event_list.count {
if let event = event_list[i] as? NSDictionary {
self.compareDate(date: (event["date"] as? String)!)
self.EventsData.append(
Event(
eventId: event["eventId"] as? String,
eventName:event["details"] as? String,
eventDate: event["date"] as? String
)
)
}
}
self.do_refresh()
}
if I can call this function
func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {
let dateString = self.dateFormatter2.string(from: date)
print("this count first ",self.EventsData.count)
}
Result:
this count first 0
this count first 0
this count first 0
After Scrolling the calender its showing
this count first 26
this count first 26
this count first 26
Upvotes: 0
Views: 165
Reputation: 899
Please Try This Code
var jsondarray = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
getdairyDetails()
}
func getdairyDetails()
{
var userDic : [String : AnyObject] = [:]
if errorCode == "0" {
if let event_list = jsonData["events"] as? NSArray {
for i in 0 ..< event_list.count {
if let event = event_list[i] as? NSDictionary {
self.compareDate(date: (event["date"] as? String)!)
userDic = [
"eventId": event["eventId"] as? String,
"eventName":event["details"] as? String,
"eventDate": event["date"] as? String
]
jsondarray.add(userDic)
}
}
}
self.do_refresh()
}
func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {
let dateString = self.dateFormatter2.string(from: date)
print("this count first ",self.jsondarray.count)
}
Upvotes: 1