gpt4 book ai didi

uiview - 单点触控 : how to add UIView to DialogViewController

转载 作者:行者123 更新时间:2023-12-02 22:25:25 25 4
gpt4 key购买 nike

在我的一个屏幕中,我需要将 UIView(带有一些标签和按钮)添加到 DialogViewController。原因是我没有为此使用 TableView header ,因为我不希望此 View 在表格滚动时滚动。

如果我将自定义 View 添加到导航栏,我可以实现这一点,但是我的 View 将不会收到任何触摸(导航 Controller 吃掉它们)。

我还尝试将自定义 View 添加到 DialogsViewController 父 Controller ,虽然它可以工作,但在 LoadView() 中调整 tableview 框架的大小没有做任何事情。

是否有任何其他方法可以将自定义 View 添加到 DialogViewController?

谢谢。

最佳答案

要添加不滚动的标题,您可以创建一个 Controller ,其 View 包含您要添加的其他 View 以及 DialogViewController 的 View 。例如,以下简单示例将 UILabel 与 DialogViewController 的 View 一起添加为附加 Controller (在本例中称为 容器)的 subview :

   [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);
}
}

这是显示模拟器中结果的屏幕截图: enter image description here

关于uiview - 单点触控 : how to add UIView to DialogViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13060362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com