我有一个带有中等大小故事板的应用程序,它足够复杂,我不想过多地弄乱它。
我想复制这个故事板并更改配色方案并让用户选择要使用的配色方案。
我的问题是:我可以以编程方式选择启动时默认使用的情节提要吗?如果是 - 我该怎么做?
我看了一个有点相关的问题:Storyboards Orientation Support in Xcode 4.5 and iOS 6.x ?
基于该代码,我做了一个扩展方法:
static bool IsStoryboardLoading {get;set;}
public static T ConsiderSwitchingStoryboard<T> (this UIViewController from) where T: UIViewController
{
if (!IsStoryboardLoading && LocalStorage.Instance.IsWhiteScheme && false) {
try {
IsStoryboardLoading = true;
UIStoryboard storyboard = UIStoryboard.FromName ("MainStoryboard_WHITE", NSBundle.MainBundle);
T whiteView = storyboard.InstantiateViewController (typeof(T).Name) as T;
from.PresentViewController (whiteView, false, null);
return whiteView;
} finally {
IsStoryboardLoading = false;
}
}
return null;
}
}
然后我在ViewDidAppear
覆盖中使用它:
public override void ViewDidAppear (bool animated)
{
this.ConsiderSwitchingStoryboard<MyViewController> ();
}
push
此代码在某些情况下有效,但在其他情况下会在执行segue时导致错误:
NSGenericException Reason: Could not find a navigation controller for segue 'segSearchResults'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr_IntPtr (intptr,intptr,intptr,intptr)