在DialogViewController LoadView方法上设置TableView.Frame似乎没有任何作用,这是有原因的吗?
目前,为了解决这个问题,我为顶部边距设置了TableView.ContentInset,为底部边距设置了TableView.TableFooterView,但这种方法的问题是,滚动条不会从表格边界的位置开始/结束,例如,它将位于底部的TabBar下,等等。
有没有办法在DialogViewController中手动设置TableView frame,如果没有,为什么?
谢谢。
更新:我期望的示例代码应该工作得很好,例如更改TableView框架?注意:如果我在ViewDidAppear中设置了Frame,那么它就可以工作,但我需要它在ViewDidLoad中工作。
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);
}
}
}发布于 2013-07-30 16:51:20
您是否尝试过将TableView的AutoresizingMask属性设置为UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
如果这不起作用,请尝试检查TableView的Frame、ContentSize和ContentInset属性。看起来TableView.Frame.Bottom位于你的TabBar下,这就是为什么你不能一直滚动到你的TableView的末尾。
如何更改TableView.Frame属性?例如,如果您想要更改Frame.X,则必须像这样更改整个Frame:
RectangleF frame = TableView.Frame
frame.X = 100;
TableView.Frame = frame;而不是简单地更改Frame.X
TableView.Frame.X = 100;发布于 2013-08-06 10:14:04
好了,我想我找到了问题的答案。
DialogViewController是从UITableViewController继承而来的,据我所知,你不能在UITableViewController中改变TableView框架。
要实现这一点,DialogViewController需要从UIViewController继承,老实说,我不确定为什么不这样做。
https://stackoverflow.com/questions/17918037
复制相似问题