首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用单点触控更改DialogViewController TableView高度

使用单点触控更改DialogViewController TableView高度
EN

Stack Overflow用户
提问于 2013-07-29 15:14:35
回答 2查看 1.1K关注 0票数 1

在DialogViewController LoadView方法上设置TableView.Frame似乎没有任何作用,这是有原因的吗?

目前,为了解决这个问题,我为顶部边距设置了TableView.ContentInset,为底部边距设置了TableView.TableFooterView,但这种方法的问题是,滚动条不会从表格边界的位置开始/结束,例如,它将位于底部的TabBar下,等等。

有没有办法在DialogViewController中手动设置TableView frame,如果没有,为什么?

谢谢。

更新:我期望的示例代码应该工作得很好,例如更改TableView框架?注意:如果我在ViewDidAppear中设置了Frame,那么它就可以工作,但我需要它在ViewDidLoad中工作。

代码语言:javascript
复制
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using MonoTouch.Dialog;

namespace Test
{
    [Register ("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
        UIWindow window;
        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            var vc = new MainViewController ();
            window = new UIWindow (UIScreen.MainScreen.Bounds);
            window.RootViewController = vc;
            window.MakeKeyAndVisible ();
            return true;
        }
    }

    [Register]
    public class MainViewController : DialogViewController
    {
        public MainViewController (): base (UITableViewStyle.Plain, new RootElement (""))
        {
            TableView.AutoresizingMask = UIViewAutoresizing.None;

            Section s = new Section ("Section 1");
            Root.Add (s);

            StringElement el = new StringElement ("Element 1");
            s.Add (el);

            el = new StringElement ("Element 2");
            s.Add (el);

            s = new Section ("Section 2");
            Root.Add (s);

            el = new StringElement ("Element 1");
            s.Add (el);

            el = new StringElement ("Element 2");
            s.Add (el);
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            TableView.Frame = new RectangleF (0, 120, TableView.Frame.Width, TableView.Frame.Height - 120);
        }
    }
}
EN

回答 2

Stack Overflow用户

发布于 2013-07-30 16:51:20

您是否尝试过将TableViewAutoresizingMask属性设置为UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

如果这不起作用,请尝试检查TableViewFrameContentSizeContentInset属性。看起来TableView.Frame.Bottom位于你的TabBar下,这就是为什么你不能一直滚动到你的TableView的末尾。

如何更改TableView.Frame属性?例如,如果您想要更改Frame.X,则必须像这样更改整个Frame

代码语言:javascript
复制
RectangleF frame = TableView.Frame
frame.X = 100;
TableView.Frame = frame;

而不是简单地更改Frame.X

代码语言:javascript
复制
TableView.Frame.X = 100;
票数 1
EN

Stack Overflow用户

发布于 2013-08-06 10:14:04

好了,我想我找到了问题的答案。

DialogViewController是从UITableViewController继承而来的,据我所知,你不能在UITableViewController中改变TableView框架。

要实现这一点,DialogViewController需要从UIViewController继承,老实说,我不确定为什么不这样做。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17918037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档