2012-10-25 7 views
2

내 화면 중 하나에서 DialogViewController에 UIView (일부 레이블 및 버튼 포함)를 추가해야합니다. 그 이유는 TableView 헤더를 사용하지 않는다는 것입니다. 테이블을 스크롤 할 때이 뷰를 스크롤하지 않으려 고합니다.Monotouch : DialogViewController에 UIView를 추가하는 방법

사용자 지정보기를 탐색 모음에 추가하면 내보기가 아무런 영향을받지 않습니다 (탐색 컨트롤러가이를 받음).

또한 DialogsViewController 상위 컨트롤러에 사용자 지정보기를 추가했지만 작동하는 동안 LoadView()에서 tableview의 프레임 크기를 조정하면 아무 것도 수행하지 않습니다.

DialogViewController에 사용자 지정보기를 추가하는 다른 방법이 있습니까?

감사합니다.

답변

5

스크롤하지 않는 헤더를 추가하려면 추가하려는 추가 뷰와 DialogViewController 뷰가 모두 포함 된 컨트롤러를 만들 수 있습니다.

[Register ("AppDelegate")] 
    public partial class AppDelegate : UIApplicationDelegate 
    { 
     UIWindow window; 
     MyDialogViewController dvc; 
     UIViewController container; 
     float labelHeight = 30; 

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

      container = new UIViewController(); 

      container.View.AddSubview (new UILabel (new RectangleF (0, 0, UIScreen.MainScreen.Bounds.Width, labelHeight)){ 
       Text = "my label", BackgroundColor = UIColor.Green}); 

      dvc = new MyDialogViewController (labelHeight); 

      container.View.AddSubview (dvc.TableView); 

      window.RootViewController = container; 

      window.MakeKeyAndVisible(); 

      return true; 
     } 

    } 

그 다음 DialogViewController가있는 viewDidLoad 방법에서의 TableView의 높이를 조정한다 : 예를 들어 다음의 간단한 예는 (이 경우에는 컨테이너함) 추가 제어기 파단로 DialogViewController의 도면과 함께 UILabel의 추가

public partial class MyDialogViewController : DialogViewController 
    { 
     float labelHeight; 

     public MyDialogViewController (float labelHeight) : base (UITableViewStyle.Grouped, null) 
     { 
      this.labelHeight = labelHeight; 

      Root = new RootElement ("MyDialogViewController") { 
       new Section(){ 
        new StringElement ("one"), 
        new StringElement ("two"), 
        new StringElement ("three") 
       } 
      }; 
     } 

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

      TableView.Frame = new RectangleF (TableView.Frame.Left, TableView.Frame.Top + labelHeight, TableView.Frame.Width, TableView.Frame.Height - labelHeight); 
     } 
    } 

여기 시뮬레이터의 결과를 보여주는 스크린 샷입니다 : enter image description here

+0

우수한 예를 들어 마이크를 :) – dalexsoto