在片段导航中挣扎了很多,现在已经开始了几天没有任何进展。
我有一个名为" NewsViewModel"的ViewModel;其中包含属性NewsItemWraps。这是包装器模型中的新闻列表。这只是在我的视图中显示在列表中,我希望用户能够标记新闻项并查看此新闻的详细信息。
只要用户只看到相同的NewsDetail,这就完美无缺。但是,如果您选择第1项,导航回列表,选择项目2查看详细信息,然后再次导航回列表我收到以下错误: 合同失败 - 片段标记为空!默认情况下不设置片段标记,您应该在FragmentTransaction期间添加标记或在Fragment类中覆盖UniqueImmutableCacheTag。
public override void OnBackPressed()
{
var currentFragment = SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as MvxFragment;
if (currentFragment != null && SupportFragmentManager.BackStackEntryCount >= 1)
{
SupportFragmentManager.PopBackStackImmediate(); //<-- This guy tosses the error
return;
}
if (DrawerLayout != null && DrawerLayout.IsDrawerOpen(GravityCompat.Start))
DrawerLayout.CloseDrawers();
else
base.OnBackPressed();
}
我在OnFragmentCreated中将片段添加到BackStack时尝试修改fragmentInfo上的标记,但这并没有改变任何内容。如果我在OnFragmentCreated中将它添加到这样的Backstack中,或者让“addToBackstack”&#39;样本中的bool句柄。如果它被缓存,它也不在乎。
public override void OnFragmentCreated(IMvxCachedFragmentInfo fragmentInfo, Android.Support.V4.App.FragmentTransaction transaction)
{
// You can do fragment + transaction based configurations here.
// Note that, the cached fragment might be reused in another transaction afterwards.
//Adding the fragment to the stack manually.
if (fragmentInfo.Tag.Contains(typeof(NewsDetailsViewModel).Name))
{
transaction.AddToBackStack(typeof(NewsDetailsViewModel).Name);
}
base.OnFragmentCreated(fragmentInfo, transaction);
var myCustomInfo = fragmentInfo as CustomFragmentInfo; //How the sample handles the backstack in the factory MainActivityFragmentCacheInfoFactory.
}
我在cacheFactory中的类型:
{
typeof (NewsDetailsViewModel).ToString(),
new CustomFragmentInfo(typeof (NewsDetailsViewModel).Name,
typeof (NewsDetailsFragment),
typeof (NewsDetailsViewModel), cacheFragment: false, addToBackstack: true, isRoot:false )
}
NewsViewModel中的属性:
private List<NewsItemWrap> _newsItemWraps;
public List<NewsItemWrap> NewsItemWraps
{
get { return _newsItemWraps ?? (_newsItemWraps = new List<NewsItemWrap>()); }
set { _newsItemWraps = value; RaisePropertyChanged(() => NewsItemWraps); }
}
我一直在玩Mvvmcross来修改样本:https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples
非常感谢任何指针和建议
完整筹码:
System.InvalidOperationException:合同失败 - 片段标记为 空值!默认情况下不设置片段标记,您应该在期间添加标记 FragmentTransaction或覆盖你的UniqueImmutableCacheTag 片段类。
02-19 09:38:56.795 I / MonoDroid(30813):UNHANDLED EXCEPTION:02-19 09:38:56.795 I / MonoDroid(30813):System.InvalidOperationException: 合同失败 - 片段标记为空!片段标记未设置 默认情况下,您应该在FragmentTransaction或覆盖期间添加标记 Fragment类中的UniqueImmutableCacheTag。 02-19 09:38:56.795 I / MonoDroid(30813):at MvvmCross.Droid.Support.V7.Fragging.Fragments.MvxFragmentExtensions.RegisterFragmentViewToCacheIfNeeded (IMvxFragmentView fragmentView)[0x0005a] in:0 02-19 09:38:56.795 I / MonoDroid(30813):at MvvmCross.Droid.Support.V7.Fragging.Fragments.MvxBindingFragmentAdapter.HandleCreateCalled (System.Object sender,MvvmCross.Platform.Core.MvxValueEventArgs
1 bundleArgs) [0x00024] in <filename unknown>:0 02-19 09:38:56.795 I/MonoDroid(30813): at MvvmCross.Platform.Core.MvxDelegateExtensionMethods.Raise[T] (System.EventHandler
1 eventHandler,System.Object sender, MvvmCross.Platform.Core.T value)[0x00000] in 五:\ Xamarin \ MvvmCross \ MvvmCross \平台\平台\核心\ MvxDelegateExtensionMethods.cs:21 02-19 09:38:56.795 I / MonoDroid(30813):at MvvmCross.Droid.Support.V7.Fragging.Fragments.EventSource.MvxEventSourceFragment.OnCreate (Android.OS.Bundle savedInstanceState)[0x00014] in:0 02-19 09:38:56.795 I / MonoDroid(30813):at Android.Support.V4.App.Fragment.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv,IntPtr native__this,IntPtr native_savedInstanceState) [0x00011] in:0 02-19 09:38:56.795 I / MonoDroid(30813):at(包装器动态方法) System.Object的:136761ed-d521-468a-9257-5d08a4df776b (IntPtr的,IntPtr的,IntPtr的)
答案 0 :(得分:2)
这是当前Nuget中的一个错误,并已在此提交中修复:https://github.com/MvvmCross/MvvmCross-AndroidSupport/commit/72356791714795c9d711a0c491367fd5c5ebdb82
我们很快会发布更新。