2012-05-17 1 views
4

나는이 주제에 대한 자료를 찾고 잠시 동안 웹을 둘러 보았고 내 딜레마를 해결하는 방법을 찾지 못했습니다. UIView 또는 Vice Versa에 Subview로 대화보기 컨트롤러를 추가하려면 어떻게해야합니까?

나는 대화 뷰 컨트롤러가 그 뿌리는 단순히 아이폰 음악 노래 스크롤 뷰가 배치되는 방식과 유사 문자열의 목록이 표시됩니다. 내가 필요로하는 것은 화면의 상단에 위치한 서브 뷰와 그 아래에있는 스크롤 가능한 DVC입니다. 상위 뷰가 통계를 보유 할 것이기 때문에 사용자가 루트 요소를 스크롤 할 수 있도록 항상 상위 뷰에 있어야합니다.

서브 뷰 추가를 시도했지만 간단히 그 아래의 dvc와 겹치지 만 UI 뷰에 서브 뷰로 dvc를 추가하는 방법을 찾지 못했습니다.

도움을 주시면 감사하겠습니다. 이를 달성하기 위해 필요한 것은

답변

10

이 서브 뷰 컨트롤러를 호스팅하는 단일 루트 뷰 컨트롤러입니다. 하나의 하위 뷰에는 창 상단에 통계가 포함됩니다. 아래쪽 하위 뷰에는 대화 상자보기를 보유하는 탐색 컨트롤러가 포함되어 있습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 

using MonoTouch.Foundation; 
using MonoTouch.UIKit; 
using MonoTouch.Dialog; 
using System.Drawing; 

namespace delete201205203 
{ 
    [Register ("AppDelegate")] 
    public partial class AppDelegate : UIApplicationDelegate 
    { 
     UIWindow window; 
     MyUIViewController _mvc; 

     public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
     { 
      window = new UIWindow (UIScreen.MainScreen.Bounds); 

      _mvc = new MyUIViewController(); 

      window.RootViewController = _mvc; 
      window.MakeKeyAndVisible(); 

      return true; 
     } 
    } 

    public class MyUIViewController : UIViewController 
    { 
     MyDialogViewController _dvc; 
     UINavigationController _nav; 
     StatisticsViewController _statistics; 

     public override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 

      var root = new RootElement ("Root") { 
       new Section ("Section") { 
        new EntryElement ("caption", "placeholder", ""), 
        new RootElement ("Root 2") { 
         new Section ("Section") { 
          new EntryElement ("caption", "placeholder", ""), 
          new StringElement ("Back",() => { 
           _nav.PopViewControllerAnimated (true); 
          }) 
         } 
        } 
       } 
      }; 

      _dvc = new MyDialogViewController (root); 
      _nav = new UINavigationController (_dvc); 
      _nav.SetNavigationBarHidden (true, false); 
      _nav.View.Frame = new RectangleF (0, 70f, 
               this.View.Bounds.Width, 
               this.View.Bounds.Height -70f); 

      _statistics = new StatisticsViewController(); 
      _statistics.View.Frame = new RectangleF (0, 0, 
               this.View.Bounds.Width, 
               70f); 

      this.AddChildViewController (_nav); 
      this.View.AddSubview (_nav.View); 

      this.AddChildViewController (_statistics); 
      this.View.AddSubview (_statistics.View); 
     } 

     public override void ViewWillLayoutSubviews() 
     { 
      base.ViewWillLayoutSubviews(); 
      _nav.View.Frame = new RectangleF (0, 70f, 
               this.View.Bounds.Width, 
               this.View.Bounds.Height -70f); 

      _statistics.View.Frame = new RectangleF (0, 0, 
               this.View.Bounds.Width, 
               70f); 
     } 

     public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 
     { 
      return true; 
     } 
    } 

    public class StatisticsViewController : UIViewController 
    { 
     UILabel _label; 
     public override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 
      this.View.BackgroundColor = UIColor.White; 

      _label = new UILabel (new RectangleF (this.View.Bounds.Width * .5f - 50f, 
                this.View.Bounds.Height * .5f -10f, 
                100f, 20f)); 
      _label.AutoresizingMask = UIViewAutoresizing.FlexibleMargins; 

      _label.Text = "statistics"; 
      this.View.AddSubview (_label); 

     } 

     public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 
     { 
      return true; 
     } 
    } 

    // This overrde is needed to ensure the pop view animation 
    // works correctly in landscape mode 
    public class MyDialogViewController : DialogViewController 
    { 
     public MyDialogViewController (RootElement root) : base (root) {} 
     public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 
     { 
      return true; 
     } 
    } 
} 
+0

고마워요. 제가 한 일이었습니다. 내가 시도한 것은이 라인을 따라했지만 몇 가지 부분을 놓치고 있었다. 고맙습니다! – MattNotEquals0

+0

나는 같은 것을 사용했다. 하지만 한 가지 문제가 있습니다. Dialogview 컨트롤러는 완벽하게 나타납니다 만, 엔트리 요소가 많은 경우, 맨 아래 엔트리 요소까지 스크롤하면 키보드가 그 요소를 숨기고 있습니다. 그 요소는 자동 스크롤하지 않습니다. 어느 누구도 어떤 생각을 갖고 있습니까? 나는 동적 인 형태를 창조한다. – SoftSan

+0

이것은 많은 도움이됩니다 !! 너는 나의 많은 시간을 구했다 !! 감사합니다 :) – SoftSan

관련 문제