I need to change the cell background color when a user taps a cell in the month view. In MonthViewDayTapped, I'm currently returning false, to effectively disable the day view, since we don't need that. If there's no property/method, is there any trick I can use to set the cell color? Ideally, I'd be able to get to each of the UIView objects for each cell in the calendar somehow, and have full access, since not everybody is going to use a calendar to show appointments (show images, etc.), but the color would be nice to set in particular. Thanks!
Ok, i figured it out. Looks like Xamarin can occasionally lose the connection with a view thats created with a IntPtr.
So instead, we should just store off the ptr:
IntPtr _prevSelectedDayViewPtr;
if (_prevSelectedDayViewPtr != null) { UIView prevDayView = new UIView (_prevSelectedDayViewPtr); prevDayView.BackgroundColor = UIColor.Clear; } UIView multiMonthView = (UIView)calView.ValueForKey (new NSString("_monthView")); IntPtr dateInfoPtr = Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr ((new Class ("DateInfo")).Handle, (new Selector (new NSString ("resolveInfoForDate:usingCalendarView:"))).Handle, date.Handle, calView.Handle); IntPtr monthViewPtr = Messaging.IntPtr_objc_msgSend_IntPtr (multiMonthView.Handle, new Selector ("resolveMonthViewForDate:").Handle, dateInfoPtr); IntPtr monthViewDayPtr = Messaging.IntPtr_objc_msgSend_IntPtr (monthViewPtr, new Selector ("resolveMonthViewDayForDate:").Handle, dateInfoPtr); _prevSelectedDayViewPtr = monthViewDayPtr; UIView day = new UIView (monthViewDayPtr); day.BackgroundColor = UIColor.Orange;
-SteveZ
Hey Paul,
I went back and played around with it again, and I was able to reproduce it.
I'll try and figure out whats going on and get back to you.
Hi Paul,
I was playing around with the code snippet i posted, and its not reproducing on my end.
As long as you're not losing _prevSelectedDayView then you'll always be able reset it. Can you validate that _prevSelectedDayView is not getting set to null somewhere? If you were to lose that value, then i could see it sticking, but that would be the only case. That view object is only created once when the control is created, so it wouldn't be getting lost on the control side.
We use this code (the xamarin version) in our application, however there seems to be a defect. Occasionally, if you tap several cells the colour seems to "stick" so we end up with two or more highlighted cells. Could you let me know if there's a resolution for this, or if it's a known defect and when there will be a fix available?Thanks
Hi Michael,
Sure! I meant to do that originally, but when from your last reply, I just assumed you got it working:
using MonoTouch.ObjCRuntime;
public class CalViewDelegate :IGCalendarViewDelegate { UIView _prevSelectedDayView; public override bool MonthViewDayTapped (IGCalendarView calView, NSDate date) { if (_prevSelectedDayView != null) _prevSelectedDayView.BackgroundColor = UIColor.Clear; UIView multiMonthView = (UIView)calView.ValueForKey (new NSString("_monthView")); IntPtr dateInfoPtr = Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr ((new Class ("DateInfo")).Handle, (new Selector (new NSString ("resolveInfoForDate:usingCalendarView:"))).Handle, date.Handle, calView.Handle); IntPtr monthViewPtr = Messaging.IntPtr_objc_msgSend_IntPtr (multiMonthView.Handle, new Selector ("resolveMonthViewForDate:").Handle, dateInfoPtr); IntPtr monthViewDayPtr = Messaging.IntPtr_objc_msgSend_IntPtr (monthViewPtr, new Selector ("resolveMonthViewDayForDate:").Handle, dateInfoPtr); _prevSelectedDayView = new UIView (monthViewDayPtr); _prevSelectedDayView.BackgroundColor = UIColor.Orange; return false; } }