Xamarin.ios 将Mvvmcross绑定与MonoTouch.Dialog RadioGroup一起使用
基于以下问题: 我尝试实现一个可绑定的部分,以允许异步调用根据前面的选择更新无线组列表Xamarin.ios 将Mvvmcross绑定与MonoTouch.Dialog RadioGroup一起使用,xamarin.ios,mvvmcross,monotouch.dialog,Xamarin.ios,Mvvmcross,Monotouch.dialog,基于以下问题: 我尝试实现一个可绑定的部分,以允许异步调用根据前面的选择更新无线组列表 public class BindableLocalitySection : Section { private IEnumerable _itemsSource; private MvxNotifyCollectionChangedEventSubscription _subscription; public BindableLocalitySection() :
public class BindableLocalitySection : Section
{
private IEnumerable _itemsSource;
private MvxNotifyCollectionChangedEventSubscription _subscription;
public BindableLocalitySection()
: base()
{
}
public BindableLocalitySection(string caption)
: base(caption)
{
}
[MvxSetToNullAfterBinding]
public IEnumerable ItemsSource
{
get { return _itemsSource; }
set { SetItemsSource(value); }
}
protected virtual void SetItemsSource(IEnumerable value)
{
if (_itemsSource == value)
return;
if (_subscription != null)
{
_subscription.Dispose();
_subscription = null;
};
_itemsSource = value;
if (_itemsSource != null && !(_itemsSource is IList))
MvxBindingTrace.Trace(MvxTraceLevel.Warning,
"Binding to IEnumerable rather than IList - this can be inefficient, especially for large lists");
var newObservable = _itemsSource as INotifyCollectionChanged;
if (newObservable != null)
_subscription = newObservable.WeakSubscribe(OnItemsSourceCollectionChanged);
NotifyDataSetChanged();
}
private void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
NotifyDataSetChanged();
}
private void NotifyDataSetChanged()
{
var newElements = new List<Element>();
if (_itemsSource != null)
{
foreach (var item in _itemsSource)
{
var a = (BaseSearchViewModel.Locality)item;
var element = new RadioElement(a.Name);
newElements.Add((Element) element);
}
}
Elements.Clear();
Elements.AddRange(newElements);
var root = this.Parent as RootElement;
if (root == null)
{
root = this.GetImmediateRootElement();
}
if (root != null && root.TableView != null)
{
root.TableView.ReloadData();
}
}
}
列表将更新,我可以看到新绑定的元素,但当我选择列表时,整个应用程序将崩溃
Object reference not set to an instance of an object
at CrossUI.Touch.Dialog.Elements.RadioElement.SubscribeToRoot () [0x00000] in <filename unknown>:0
at CrossUI.Touch.Dialog.Elements.RadioElement.GetCellImpl (MonoTouch.UIKit.UITableView tv) [0x00000] in <filename unknown>:0
at CrossUI.Touch.Dialog.Elements.Element.GetCell (MonoTouch.UIKit.UITableView tv) [0x00000] in <filename unknown>:0
at CrossUI.Touch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at <<Removed Name>>.Main (System.String[] args) [0x00008] in <<Removed Path>>Main.cs:17
对象引用未设置为对象的实例
在:0中的CrossUI.Touch.Dialog.Elements.RadioElement.SubscribeToRoot()[0x00000]处
在CrossUI.Touch.Dialog.Elements.RadioElement.GetCellImpl(MonoTouch.UIKit.UITableView tv)[0x00000]中:0
在CrossUI.Touch.Dialog.Elements.Element.GetCell(MonoTouch.UIKit.UITableView tv)[0x00000]中:0
在Suthux.Touk.Deal.DealVIEWVisualSudio.SoCECE.GETCLE(MyOrth.UIKIT.UITababVIEW TabLVIEW,MyTrask.Buffig.NSnxDebug索引路径)[0x00] in:0
at(包装器管理为本机)MonoTouch.UIKit.UIApplication:UIApplicationMain(int,string[],intptr,intptr)
在/Developer/MonoTouch/Source/MonoTouch/src/UIKit/UIApplication.Main中的MonoTouch.UIKit.UIApplication.Main(System.String[]args,System.String principalClassName,System.String delegateClassName)[0x0004c]
Main.cs:17中的at.Main(System.String[]args)[0x00008]
如果有任何帮助,我们将不胜感激。Ok中有一个无线电组示例,因此这看起来与我发布的问题相同-您是否可以分享您的解决方案?我找不到Stuart所指的广播组示例。
Object reference not set to an instance of an object
at CrossUI.Touch.Dialog.Elements.RadioElement.SubscribeToRoot () [0x00000] in <filename unknown>:0
at CrossUI.Touch.Dialog.Elements.RadioElement.GetCellImpl (MonoTouch.UIKit.UITableView tv) [0x00000] in <filename unknown>:0
at CrossUI.Touch.Dialog.Elements.Element.GetCell (MonoTouch.UIKit.UITableView tv) [0x00000] in <filename unknown>:0
at CrossUI.Touch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at <<Removed Name>>.Main (System.String[] args) [0x00008] in <<Removed Path>>Main.cs:17