要添加不滚动的标题,您可以创建一个控制器,其视图包含您要添加的其他视图以及 DialogViewController 的视图。例如,以下简单示例将 UILabel 与 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的高度:
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);
}
}
这是显示模拟器中结果的屏幕截图: