[MonoTouch] How do I make DateTimeElement datePicker show up in a popover?

2013-02-20 Thread Xy
The default date picker looks like this:

I'd like it to appear in a popover instead, so I created my own class:
public class CustomDateTimeElement : DateTimeElement{   static 
bool
UserInterfaceIdiomIsPhone { get { return
UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }  
}   UIPopoverController PopoverVC;  
public CustomDateTimeElement (string
caption, DateTime date) : base(caption, date)   {   
}   public override void
Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{   if (UserInterfaceIdiomIsPhone) {
base.Selected(dvc, tableView, path);
}   else {  // Trying to make 
keyboard go away. doesn't work
tableView.CellAt(path).BecomeFirstResponder();  if 
(datePicker == null) {   
datePicker = CreatePicker();}   
// Put picker in a view controller  
var navVC = new UIViewController(); 
navVC.View.BackgroundColor =
UIColor.Black;  navVC.View.AddSubview(datePicker);  
// Create a popover
that fits picker and show itPopoverVC = new 
UIPopoverController(navVC) {
PopoverContentSize = new System.Drawing.SizeF(320, 215) 
};  
PopoverVC.PresentFromRect(tableView.RectForRowAtIndexPath(path), tableView,
UIPopoverArrowDirection.Any, true); }   }   
}The picker appears fine, but
when I change the date value, the corresponding DateTimeElement value does
NOT change. Also, as noted above, I was unsuccessful in making any text
field resign first responder. Could anyone give me some guidance on how to
fix these two issues? 



--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/How-do-I-make-DateTimeElement-datePicker-show-up-in-a-popover-tp4658091.html
Sent from the MonoTouch mailing list archive at Nabble.com.___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] How do I make DateTimeElement datePicker show up in a popover?

2013-02-20 Thread Xy
Updated original post to correct code formatting



--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/How-do-I-make-DateTimeElement-datePicker-show-up-in-a-popover-tp4658091p4658092.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] How do I make DateTimeElement datePicker show up in a popover?

2013-02-21 Thread Jeff Stedfast
Hi Xy,

I wrote my own Element subclass for this in my own side-project. You can
find the source for my DateEntryElement here:

https://github.com/jstedfast/FlightLog/blob/master/FlightLog/Elements/DateEntryElement.cs

Hope that helps!

Jeff

On Thu, Feb 21, 2013 at 2:34 AM, Xy  wrote:

> Updated original post to correct code formatting
>
>
>
> --
> View this message in context:
> http://monotouch.2284126.n4.nabble.com/How-do-I-make-DateTimeElement-datePicker-show-up-in-a-popover-tp4658091p4658092.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> ___
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] How do I make DateTimeElement datePicker show up in a popover?

2013-02-21 Thread Xy
Hi Jeff, 

Thanks to your code, I added these two methods to make value update
correctly:
public override UIDatePicker CreatePicker ()
{
var picker = base.CreatePicker ();

if (!UserInterfaceIdiomIsPhone) {
picker.ValueChanged += HandleValueChanged;
}
return picker;
}

void HandleValueChanged (object sender, EventArgs e)
{
this.DateValue = (DateTime) ((UIDatePicker)sender).Date;
GetImmediateRootElement().Reload(this, 
UITableViewRowAnimation.None);
}

Do you have any suggestion for dismissing the keyboard when the picker is
up?



--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/How-do-I-make-DateTimeElement-datePicker-show-up-in-a-popover-tp4658091p4658101.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] How do I make DateTimeElement datePicker show up in a popover?

2013-02-21 Thread Xy
Never mind. I figured out a way to show the picker on dismissing the
keyboard. Basically added these two observers in the constructor (and
removed them in Dispose()):
KeyboardShowObserver =
NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidShowNotification,
delegate {
IsKeyboardVisible = true;
});

KeyboardHideObserver =
NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidHideNotification,
delegate {
IsKeyboardVisible = false;

if (ShouldShowPicker) {
ShowPicker(WeakTableView, WeakPath);

// Don't keep these around
ShouldShowPicker = false;
WeakTableView = null;
WeakPath = null;
}
});

I set the variables ShouldShowPicker, WeakTableView, and WeakPath in
Selected() if keyboard is visible. Let me know if there's a better way.



--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/How-do-I-make-DateTimeElement-datePicker-show-up-in-a-popover-tp4658091p4658102.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch