ノート:
多くのコード/診断があります。最初に問題について説明し、続いて多くのコード ビハインド (質問への回答を支援するため) を説明し、最後に 3 つの異なる診断ブロックを追加して、さらに質問に回答できるようにします。明らかに、読者がすべてを読み通すことを期待していません。
問題:
アプリを実行して同じビューを表示するたびに (閉じた後)、コンソール出力には以前のバインディングがまだ存在することが表示されます。
詳細:
私が表示しているビューは次のとおりです。ViewModel にバインドされたソースを持つテーブルビューがあり、各セルには ViewModel にバインドされた左右のラベルがあります。
上記のビューをモーダル ポップオーバー ビューとして作成しました。各セルは、フィールドを編集できる新しいビューにユーザーをナビゲートします。新しいビューに移動して「戻る」ボタンで移動しても、問題は発生しません (私の知る限り)。ユーザーがボタンを押してモーダル ポップオーバーを閉じる (「キャンセル」など) と、次にビューが表示されたときに、古いバインディングが存在するように見えます。診断の下を見ると、値がどのように繰り返されるかがわかります。理由がわかりません。
テーブルビューを作成し、バインディングに問題があるセルをGetOrCreateCellFor
新しく作成します。TimesheetOptionCell
コードビハインド:
私の中ViewDidLoad()
で私TimesheetEntryView
は設定しますItemsSource
var source = new TimesheetTableSource (TableView, this);
var set = this.CreateBindingSet<TimesheetEntryView, TimesheetEntryViewModel> ();
set.Bind (source).For (src => src.ItemsSource).To (vm => vm.Options);
set.Apply ();
TableView.Source = source;
私の中でTimesheetTableSource
:
ObservableCollection<ViewModelBase> _options;
public override System.Collections.IEnumerable ItemsSource
{
get
{
return _options;
}
set
{
_options = (ObservableCollection<ViewModelBase>)value;
if (_options != null)
{
this.ReloadTableData ();
}
}
}
public override int NumberOfSections (UITableView tableView)
{
return 3;
}
public override int RowsInSection (UITableView tableview, int section)
{
if (section == 0)
{
return _options.Count;
}
else if (section == 1)
{
return 2;
}
else if (section == 2)
{
return 1;
}
else
{
return 0;
}
}
protected override UITableViewCell GetOrCreateCellFor (UITableView tableView, NSIndexPath indexPath, object item)
{
if(indexPath.Section == 0)
{
return TimesheetOptionCell.Create ();
}
GenericOneLabelCell cell = GenericOneLabelCell.Create ();
if (indexPath.Section == 1 && indexPath.Row == 0)
{
cell.LabelText = "Save";
var set = _timesheetView.CreateBindingSet<TimesheetEntryView, TimesheetEntryViewModel> ();
set.Bind (cell).For (cll => cll.CellEnabled).To (vm => vm.SaveEnabled);
set.Apply ();
}
else if (indexPath.Section == 1 && indexPath.Row == 1)
{
cell.LabelText = "Apply";
var set = _timesheetView.CreateBindingSet<TimesheetEntryView, TimesheetEntryViewModel> ();
set.Bind (cell).For (cll => cll.CellEnabled).To (vm => vm.SaveEnabled);
set.Apply ();
}
return cell;
}
私の中でTimesheetOptionCell
:
public TimesheetOptionCell (IntPtr handle) : base (handle)
{
this.DelayBind (() =>
{
//set.bind(<label/textView>) implicitly adds .For("Text")
var set = this.CreateBindingSet<TimesheetOptionCell, OptionViewModelBase>();
set.Bind(FieldDescriptionTextView).To(option => option.OptionValue);
set.Bind(FieldTitleLabel).To(option => option.Title);
set.Apply();
});
}
public static TimesheetOptionCell Create ()
{
return (TimesheetOptionCell)Nib.Instantiate (null, null) [0];
}
診断:
ビューを初めて表示するのは次のとおりです。
2013-08-06 09:07:13.824 FCXiOSv2[16478:21e03] mvx: Diagnostic: 6.70 Showing ViewModel TimesheetEntryViewModel
2013-08-06 09:07:13.825 FCXiOSv2[16478:21e03] TouchNavigation: Diagnostic: 6.70 Navigate requested
2013-08-06 09:07:13.840 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.72 Receiving setValue to System.Collections.ObjectModel.ObservableCollection`1[FCX.Core.ViewModels.ViewModelBase]
2013-08-06 09:07:13.873 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.75 Receiving setValue to 7/23/2013
2013-08-06 09:07:13.874 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.75 Receiving setValue to Date Worked
2013-08-06 09:07:13.881 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.76 Receiving setValue to 0:00
2013-08-06 09:07:13.882 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.76 Receiving setValue to Time Worked
2013-08-06 09:07:13.888 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.77 Receiving setValue to
2013-08-06 09:07:13.889 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.77 Receiving setValue to Company
2013-08-06 09:07:13.894 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.77 Receiving setValue to
2013-08-06 09:07:13.894 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.77 Receiving setValue to Description
2013-08-06 09:07:13.899 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.78 Receiving setValue to False
2013-08-06 09:07:13.903 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 6.78 Receiving setValue to False
2回目以降、次のようになります。
2013-08-06 09:17:43.965 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to
2013-08-06 09:17:43.966 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to
2013-08-06 09:17:43.967 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to
2013-08-06 09:17:43.967 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to
2013-08-06 09:17:43.968 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to
2013-08-06 09:17:43.969 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to 7/23/2013
2013-08-06 09:17:43.970 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to 7/23/2013
2013-08-06 09:17:43.971 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to 0:00
2013-08-06 09:17:43.972 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.85 Receiving setValue to
2013-08-06 09:17:43.972 FCXiOSv2[16478:21e03] mvx: Diagnostic: 636.85 Showing ViewModel TimesheetEntryViewModel
2013-08-06 09:17:43.973 FCXiOSv2[16478:21e03] TouchNavigation: Diagnostic: 636.85 Navigate requested
2013-08-06 09:17:44.017 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.90 Receiving setValue to System.Collections.ObjectModel.ObservableCollection`1[FCX.Core.ViewModels.ViewModelBase]
2013-08-06 09:17:44.024 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.90 Receiving setValue to 7/23/2013
2013-08-06 09:17:44.025 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.90 Receiving setValue to Date Worked
2013-08-06 09:17:44.031 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.91 Receiving setValue to 0:00
2013-08-06 09:17:44.032 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.91 Receiving setValue to Time Worked
2013-08-06 09:17:44.042 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.92 Receiving setValue to
2013-08-06 09:17:44.043 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.92 Receiving setValue to Company
2013-08-06 09:17:44.050 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.93 Receiving setValue to
2013-08-06 09:17:44.050 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.93 Receiving setValue to Description
2013-08-06 09:17:44.053 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.93 Receiving setValue to False
2013-08-06 09:17:44.055 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 636.94 Receiving setValue to False
10回目以降:
2013-08-06 09:21:08.390 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.391 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.391 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.391 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.392 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.392 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.392 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.393 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.393 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.394 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.394 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.395 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.27 Receiving setValue to
2013-08-06 09:21:08.395 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.396 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.396 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.397 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.397 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.398 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.399 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.399 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.400 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.400 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.400 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.400 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.401 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.401 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.401 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.402 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.402 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.403 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.403 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.404 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.404 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.404 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.404 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.405 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.28 Receiving setValue to
2013-08-06 09:21:08.406 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.407 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.407 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.408 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.408 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.409 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.409 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.410 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.410 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to
2013-08-06 09:21:08.411 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.412 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.412 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.413 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.413 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.414 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.414 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.415 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.29 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.415 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.416 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.416 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.417 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.417 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.418 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.418 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.419 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.419 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.420 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.421 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.421 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.422 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.422 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.423 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.424 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.424 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.425 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.30 Receiving setValue to 0:00
2013-08-06 09:21:08.425 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to 0:00
2013-08-06 09:21:08.426 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.426 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.427 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.427 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.427 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.427 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.428 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.428 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.428 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to
2013-08-06 09:21:08.428 FCXiOSv2[16478:21e03] mvx: Diagnostic: 841.31 Showing ViewModel TimesheetEntryViewModel
2013-08-06 09:21:08.429 FCXiOSv2[16478:21e03] TouchNavigation: Diagnostic: 841.31 Navigate requested
2013-08-06 09:21:08.433 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.31 Receiving setValue to System.Collections.ObjectModel.ObservableCollection`1[FCX.Core.ViewModels.ViewModelBase]
2013-08-06 09:21:08.440 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.32 Receiving setValue to 7/24/2013
2013-08-06 09:21:08.441 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.32 Receiving setValue to Date Worked
2013-08-06 09:21:08.446 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.33 Receiving setValue to 0:00
2013-08-06 09:21:08.447 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.33 Receiving setValue to Time Worked
2013-08-06 09:21:08.452 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.33 Receiving setValue to
2013-08-06 09:21:08.453 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.33 Receiving setValue to Company
2013-08-06 09:21:08.459 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.34 Receiving setValue to
2013-08-06 09:21:08.460 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.34 Receiving setValue to Description
2013-08-06 09:21:08.462 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.34 Receiving setValue to False
2013-08-06 09:21:08.464 FCXiOSv2[16478:21e03] MvxBind: Diagnostic: 841.34 Receiving setValue to False
圧倒してすみません。ありがとう!