作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的一个屏幕中,我需要将 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);
}
}
这是显示模拟器中结果的屏幕截图:
关于uiview - 单点触控 : how to add UIView to DialogViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13060362/
我是一名优秀的程序员,十分优秀!