1 nested xamarin.ios monotouch.dialog dialogviewcontroller
我想在UITabViewController中使用DialogViewController.
问题:嵌套元素不显示导航栏,因此无法返回.
当我将我的类(继承自DialogViewController)推送到UINavigationController时,行为是正确的.如果我在UITabViewController的选项卡中使用相同的类(即使使用底层的UINavigationController),那么行为是错误的.
谁能帮我吗?
小智 5
虽然问题没有得到一些代码示例的帮助,但我做了一个小例子,希望能解决你的问题.在本例中,我使用了Xamarin.iOS附带的Tabbed Application模板,并将其命名为TabbingTest.
以下代码在AppDelegate中.更改FinishedLaunching方法以包含:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
var viewControllers = new UIViewController[]
{
CreateTabFor("Test", "first", new TestDialogController ()),
CreateTabFor("Second", "second", new SecondViewController ()),
};
tabBarController = new UITabBarController ();
tabBarController.ViewControllers = viewControllers;
tabBarController.SelectedViewController = tabBarController.ViewControllers[0];
window.RootViewController = tabBarController;
window.MakeKeyAndVisible ();
return true;
}
Run Code Online (Sandbox Code Playgroud)
然后添加以下方法:
private int _createdSoFarCount = 0;
private UIViewController CreateTabFor(string title, string imageName, UIViewController view)
{
var controller = new UINavigationController();
controller.NavigationBar.TintColor = UIColor.Black;
var screen = view;
SetTitleAndTabBarItem(screen, title, imageName);
controller.PushViewController(screen, false);
return controller;
}
private void SetTitleAndTabBarItem(UIViewController screen, string title, string imageName)
{
screen.Title = NSBundle.MainBundle.LocalizedString (title, title);
screen.TabBarItem = new UITabBarItem(title, UIImage.FromBundle(imageName),
_createdSoFarCount);
_createdSoFarCount++;
}
Run Code Online (Sandbox Code Playgroud)
创建一个名为TestDialogController的类并将以下代码粘贴到其中.
using System;
using MonoTouch.Dialog;
using MonoTouch.UIKit;
namespace TabbingTest
{
public class TestDialogController : DialogViewController
{
public TestDialogController (): base(UITableViewStyle.Plain,null,false)
{
var root = new RootElement ("Tabbing test"){
new Section (){
new RootElement ("First level", 0, 0) {
new Section (null, "This is the first level."){
new RootElement ("Second level", 0, 0) {
new Section (null, "This is the second level."){
new BooleanElement ("Flipflops", false)
}
}
}
}}
};
this.Root = root;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在运行应用程序.您可以看到,甚至嵌套元素也很好地显示在导航栏中.即使是多级嵌套.