Greetings, I am facing a peculiar issue with the events in my calendar.They wont show at all times, but only in transition of a view to another! Let me explain:First of all I use Xamarin.iOS. Now, I add said events using a class derived from the IGCalendarAppointmentDataSource class. It is my understanding from reading the API that when I implement this class, I must also implement the method colorForAppointmentsInIGCalendarView, however I am unable to do so, it is not found as an overrideable method from the Studio.And so, I instantiate the events to a variable:var appointments = new List();I add them one by one there, using title, startDate and endDate correctly. If it makes any difference I also use the Location and Identifier properties of IGCalendarAppointment. Then I instantiate my IGCalendarAppointmentDataSource derived, not-so-aptly named class AppointmentSource, passing the appointments.ToArray() to it. Afterwards I instantiate my NSObject[] _appointmentSources;variable, using the AppointmentSource like so: _appointmentSources = new NSObject[] { _appointmentSource };And finaly I set the AppointmentDataSources property of my calendar to the _appointmentSources.Now this is not working exactly. I am having the issue of the appointments being too shy to show all the time. When I go to the month or week views I do not see them at all, while they show up correctly in day view.However, and here's the weird part, when I am in month view and switch to the week view (I always do it like so, I do not go to the day view from the month) they show up while the transitioning effect appears. Check the following picture to understand what I am trying to say:
As you can see in the eleventh of January 2 events show up (with Greek letters) as well as one in the 12th. How can I convince them to show up all the time instead of just when the transition happens? :)
vagg
Uh I forgot to actually note that my understanding is that the whole issue originates from my inability to override the colorForAppointmentsInIGCalendarView method. If so how can I do that in C#?
Hi Vagg,
The method you want to Override in C# is: ResolveAppointmentColor. Sounds like we need to document that better. For C# we actually have some different names, as C# has different naming conventions than Obj-c.
As for the appointments not showing initially. Thats strange, can you share the code you're using for displaying the appointments? Also are you using the Sync or Async implementation?
Thanks,
-SteveZ
Goodmorning,
Ah ok great, I got that method overridden now. However, disappointingly enough, it did not resolved the issue. Following is the code I use to override the GetAppointments method:
public override NSObject[] GetAppointments(IGCalendarView calView, NSDate start, NSDate end, IGCalendarAppointmentRequestType requestType) { Double min = start.SecondsSinceReferenceDate; Double max = end.SecondsSinceReferenceDate; List<IGCalendarAppointment> returnAppts = new List<IGCalendarAppointment>(); foreach (IGCalendarAppointment appt in _appts) { NSDate startTime = appt.StartTime; double current = startTime.SecondsSinceReferenceDate; if (current >= min && current <= max) { IGCalendarAppointment calAppt = new IGCalendarAppointment(); calAppt.StartTime = startTime; calAppt.EndTime = appt.EndTime; calAppt.Location = appt.Location; calAppt.Title = appt.Title; calAppt.Color = UIColor.Cyan; returnAppts.Add(calAppt); } } return returnAppts.ToArray(); }
Notice the following line:
foreach (IGCalendarAppointment appt in _appts)
That was
foreach (NSDictionaryappt in _appts)
in some examples. However, if I have it this way I get an exception: "Specified cast is not valid" at runtime. So, what gives? :)
Thank you,
Hey Vagg,
Can you try out this sample and let me know if its working for you?
It worked perfectly, so I adjusted my logic to it.
THank you very much!