入力としてNULL値を受け入れるDateElement ...私はMT.Dを使用してDateElement
を使用する人のための誕生日を設定したいのですが、誕生日でしていますnullの場合、データがまだ収集されていないことを意味します。 DateElementにnull値または日付を受け入れる方法を知っていますか?MonoTouch.Dialog - 私は無駄にinterwebsを検索した
2
A
答えて
2
UPDATE 20140106:iOS7がリリースされているので、Appleは、日付/時刻ピッカーがコンテンツにインラインであることではなく、アクションシート、またはこの場合は、フルスクリーンオーバーレイすることを望みます。したがって、このコードはハウツーと歴史的な目的のためのものです。
[OK]を、ので、私は自分のクラスを巻か。個人的に私はセットアップ、現在の日付/時刻ピッカーがActionSheet
と同等のものを持つものとして、プロとして見ていないと思うそれに接続されている日付ピッカーがポップアップ。 MT.Dでもっと経験豊富な人がわかるかもしれませんが、私がしたのはDateTimeElement
とDateElement
のコードをコピーして、3つのボタンが上になるように修正することです:一番左のボタンはキャンセルです。ボタン領域には "Set"と "Null"ボタンがあります。右ボタンのキャプションを使用すると、クラスのctorの中で好きに設定できますが、「セット日」と「いいえ日」にデフォルト設定することができます。
共有は思いやりです!
NULLABLE DATEのTIME ELEMENT
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System;
using System.Drawing;
namespace MonoTouch.Dialog
{
public class NullableDateTimeElement : StringElement
{
private class MyViewController : UIViewController
{
private NullableDateTimeElement container;
private bool hasNullValue = false;
private bool hasBeenSet = false;
//private EventHandler nullButtonTouched;
//UIButton isNullButton;
public bool Autorotate
{
get;
set;
}
public MyViewController (NullableDateTimeElement container)
{
this.container = container;
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
//isNullButton = UIButton.FromType (UIButtonType.RoundedRect);
//isNullButton.SizeToFit();
//isNullButton.Frame = new RectangleF(this.View.Frame.Top, this.View.Frame.Left, this.View.Frame.Width - 40f, 40f);
//isNullButton.SetTitle (container.NullButtonCaption, UIControlState.Normal);
this.NavigationItem.RightBarButtonItems = new UIBarButtonItem[]
{
new UIBarButtonItem(container.NullButtonCaption, UIBarButtonItemStyle.Done, NullButtonTapped),
new UIBarButtonItem(container.SetButtonCaption, UIBarButtonItemStyle.Done, SetButtonTapped)
};
this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, CancelTapped);
this.NavigationItem.HidesBackButton = true;
//this.View.AddSubview (isNullButton);
//this.isNullButton.TouchUpInside += (nullButtonTouched = new EventHandler(nullButtonWasTouched));
}
void CancelTapped(object sender, EventArgs e)
{
hasBeenSet = false;
this.NavigationController.PopViewControllerAnimated (true);
}
void NullButtonTapped(object sender, EventArgs e)
{
hasBeenSet = true;
hasNullValue = true;
this.NavigationController.PopViewControllerAnimated (true);
}
void SetButtonTapped(object sender, EventArgs e)
{
hasBeenSet = true;
hasNullValue = false;
this.NavigationController.PopViewControllerAnimated (true);
}
public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);
if (hasBeenSet)
{
if (!hasNullValue)
this.container.DateValue = this.container.datePicker.Date;
else
this.container.DateValue = null;
}
//this.isNullButton.TouchUpInside -= nullButtonTouched;
//nullButtonTouched = null;
}
/*void nullButtonWasTouched(object sender, EventArgs e)
{
hasNullValue = true;
NavigationController.PopViewControllerAnimated (true);
}*/
public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation)
{
base.DidRotate (fromInterfaceOrientation);
this.container.datePicker.Frame = NullableDateTimeElement.PickerFrameWithSize (this.container.datePicker.SizeThatFits (SizeF.Empty));
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return this.Autorotate;
}
}
public DateTime? DateValue;
public UIDatePicker datePicker;
//public UIButton isNullButton;
public string NullButtonCaption { get; set; }
public string SetButtonCaption { get; set; }
protected internal NSDateFormatter fmt = new NSDateFormatter
{
DateStyle = NSDateFormatterStyle.Short
};
public NullableDateTimeElement (string caption, DateTime? date, string nullButtonCaption, string setButtonCaption) : base (caption)
{
this.DateValue = date;
this.Value = this.FormatDate (date);
this.NullButtonCaption = nullButtonCaption;
this.SetButtonCaption = setButtonCaption;
}
public NullableDateTimeElement(string caption, DateTime? date, string nullButtonCaption) : this(caption, date, nullButtonCaption, "Set Date")
{}
public NullableDateTimeElement(string caption, DateTime? date) : this(caption, date, "No Date", "Set Date")
{}
public override UITableViewCell GetCell (UITableView tv)
{
this.Value = this.FormatDate (this.DateValue);
UITableViewCell cell = base.GetCell (tv);
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
return cell;
}
protected override void Dispose (bool disposing)
{
base.Dispose (disposing);
if (disposing)
{
if (this.fmt != null)
{
this.fmt.Dispose();
this.fmt = null;
}
/* if (this.isNullButton != null)
{
this.isNullButton.Dispose();
this.isNullButton = null;
}*/
if (this.datePicker != null)
{
this.datePicker.Dispose();
this.datePicker = null;
}
}
}
public virtual string FormatDate (DateTime? dt)
{
if (dt.HasValue)
return this.fmt.ToString (dt.Value) + " " + dt.Value.ToLocalTime().ToShortTimeString();
else
return NullButtonCaption;
}
public virtual UIDatePicker CreatePicker()
{
return new UIDatePicker (RectangleF.Empty)
{
AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
Mode = UIDatePickerMode.DateAndTime,
Date = this.DateValue ?? DateTime.Now
};
}
private static RectangleF PickerFrameWithSize (SizeF size)
{
RectangleF applicationFrame = UIScreen.MainScreen.ApplicationFrame;
float y = 0f;
float x = 0f;
switch (UIApplication.SharedApplication.StatusBarOrientation)
{
case UIInterfaceOrientation.Portrait:
case UIInterfaceOrientation.PortraitUpsideDown:
{
x = (applicationFrame.Width - size.Width)/2f;
y = (applicationFrame.Height - size.Height)/2f - 25f;
break;
}
case UIInterfaceOrientation.LandscapeRight:
case UIInterfaceOrientation.LandscapeLeft:
{
x = (applicationFrame.Height - size.Width)/2f;
y = (applicationFrame.Width - size.Height)/2f - 17f;
break;
}
}
return new RectangleF (x, y, size.Width, size.Height);
}
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
NullableDateTimeElement.MyViewController myViewController = new NullableDateTimeElement.MyViewController (this)
{
Autorotate = dvc.Autorotate
};
this.datePicker = this.CreatePicker();
this.datePicker.Frame = NullableDateTimeElement.PickerFrameWithSize (this.datePicker.SizeThatFits (SizeF.Empty));
myViewController.View.BackgroundColor = UIColor.Black;
myViewController.View.AddSubview (this.datePicker);
dvc.ActivateController (myViewController);
}
}
}
NULLABLE DATE-ONLY ELEMENT
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace MonoTouch.Dialog
{
public class NullableDateElement : NullableDateTimeElement
{
public NullableDateElement (string caption, DateTime? date, string nullButtonCaption, string setButtonCaption) : base (caption, date, nullButtonCaption, setButtonCaption)
{
initDateOnlyPicker();
}
public NullableDateElement (string caption, DateTime? date, string nullButtonCaption) : base(caption, date, nullButtonCaption)
{
initDateOnlyPicker();
}
public NullableDateElement (string caption, DateTime? date) : base(caption, date)
{
initDateOnlyPicker();
}
void initDateOnlyPicker()
{
this.fmt.DateStyle = NSDateFormatterStyle.Medium;
}
public override string FormatDate (DateTime? dt)
{
if (dt.HasValue)
return this.fmt.ToString (dt);
else
return base.NullButtonCaption;
}
public override UIDatePicker CreatePicker()
{
UIDatePicker uIDatePicker = base.CreatePicker();
uIDatePicker.Mode = UIDatePickerMode.Date;
return uIDatePicker;
}
}
}
@Miguel、非常に合法的なビジネスがあるので、MonoTouch.Dialogにこれを追加することを検討してくださいnullの日付/時刻が必要ですが、この解決法はこのトリックを行うようです。私のコードは少しきれいにする必要がありますが、これはうまくいきます。
関連する問題
- 1. MonoTouch.Dialogを使用した検索ビュー
- 2. MonoTouch.Dialog検索バーが表示に戻ったときに検索クエリを失う
- 3. 無駄なファイルや無駄なコードを検出するためのツールPHP
- 4. 避ける、ループの最適化、無駄な検索
- 5. カピバラは、私は次のことをお願いしたいのですが、長い無駄に検索した後、ルビー
- 6. 検索バーは、私はそれを押した後、プレス検索
- 7. MonoTouch.Dialog:私は新しいDialogViewControllerを作成するためにMonoTouch.DialogのリフレクションAPIを使用していリフレクションAPI
- 8. SQLiteのアクセントを無視した検索
- 9. コメントを無視した全文検索
- 10. 無料のWeb検索APIまたはWeb検索ログ
- 11. CSSのTD:私はいくつかのことを試してみましたが、無駄にしました
- 12. Twitter検索APIが、私は成功したTwitter検索APIを実装した
- 13. 私は無駄に、このようにそれを行うにはいくつかの方法をしたリスト
- 14. Monotouch.Dialog - UISearchBar Tint
- 15. 私はグーグルで検索した
- 16. Solr検索は、私がアップロードした
- 17. PythonでCPUサイクルを無駄にする
- 18. 無駄な使用のPerl
- 19. 無駄な親のレイアウト
- 20. テンプレートタイプはC++のスペースを無駄にしますか?
- 21. 無駄なアンドロイドapp..calculatorは常に0を返します
- 22. なぜFacebook SSLの検証時に無駄なサーバーが再開しますか?
- 23. 無駄な管理のしくみ
- 24. 無駄なサーバー呼び出しwithLatestFrom
- 25. 検索ディスプレイコントローラの検索で選択されたテーブルビュー全体から行を知るには?私は私のアプリで検索したときのタイトルとして
- 26. IDataErrorInfoはメモリの無駄ですか?
- 27. Monotouch UITableViewまたはMonoTouch.Dialog
- 28. 無料または共有する画像をGoogleカスタム検索で検索
- 29. シングルラウンドブラケットを使用したソルの検索は無効です
- 30. ループ:10,000個の配列(時間を無駄にする)と1つのグローバル配列(メモリを無駄にする)