Reputation: 225
Is there a reason why setting TableView.Frame on DialogViewController LoadView method doesn't seem to do anything?
Currently to overcome this problem I set TableView.ContentInset for top and TableView.TableFooterView for bottom margins, but the problem with this approach is that scrollbar will not start/end where the table boundaries are, for example it will go "under" the TabBar at the bottom etc.
Is there a way to set TableView frame in DialogViewController manually, and if not, why?
Thank you.
Update: sample code which I expect should work fine, e.g change TableView frame? Note: if I set Frame in ViewDidAppear then it works, but I need it to work in 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);
}
}
}
Upvotes: 1
Views: 1083
Reputation: 225
Ok, I think I found the answer to my problem.
DialogViewController is inherited from UITableViewController and from what I understand you can't change TableView frame inside UITableViewController.
For this to work, DialogViewController needs to be inherited from UIViewController, to be honest not sure why it's not done this way.
Upvotes: 1
Reputation: 993
Have you tried setting the AutoresizingMask
property of your TableView
to UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
?
If this doesn't work try to inspect the Frame
, ContentSize
and ContentInset
properties of your TableView
. It looks like the TableView.Frame.Bottom
is located under your TabBar
and that's why you can't scroll all the way to the end of your TableView
.
How are you changing the TableView.Frame
property? For example if you want to change Frame.X
, you have to change the whole Frame
like this:
RectangleF frame = TableView.Frame
frame.X = 100;
TableView.Frame = frame;
instead of just changing the Frame.X
:
TableView.Frame.X = 100;
Upvotes: 1