1

UITabViewController 내부에서 DialogViewController를 사용하고 싶습니다.MonoTouch DialogViewController - UINavigationController의 첫 번째 위치에 있어야하는 이유는 무엇입니까?

문제점 : 중첩 요소는 탐색 모음을 표시하지 않으므로 되돌릴 수 없습니다.

DialogViewController에서 상속 된 내 클래스를 UINavigationController로 푸시하면 동작이 정확합니다. UITabViewController의 탭에서 동일한 클래스를 사용하는 경우 (기본 UINavigationController에서도) 동작이 잘못되었습니다.

아무도 도와 줄 수 있습니까?

답변

5

일부 코드 샘플에서는 질문에 도움이되지 않지만 필자는 질문을 해결하기 위해 간단한 예제를 작성했습니다. 이 예제에서는 Xamarin.iOS와 함께 제공되는 TabbedTest라는 탭 응용 프로그램 템플릿을 사용했습니다.

다음 코드는 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; 
} 

그런 다음 다음과 같은 방법을 추가

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++; 
} 

는 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; 
     } 
    } 
} 

이제 응용 프로그램을 실행하십시오. 중첩 된 요소조차도 탐색 모음에 잘 나타납니다. 다단계 중첩에서도.

+0

샘플 코드를 보내 주셔서 감사합니다. 하지만 NavigationController를 루트 컨트롤러로 시작하고 싶습니다. 이렇게하면 두 개의 탐색 모음이 생깁니다. 이것은 내가 원하는 것이 아닙니다. 더 이상의 제안? – Joerg