1

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);
        }
    }
}
ErnestJ
  • 167
  • 12
  • See http://stackoverflow.com/a/18282916/7561, same issue with a great solution. – ben Nov 03 '13 at 17:46

2 Answers2

1

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;
Norbert Szenasi
  • 993
  • 10
  • 24
  • Thank you. I'm changing Frame the proper way, I don't think you can even set it directly anyway. Interesting this is that setting you can table being smaller temporarily (when changing frame in LoadView), but straight away it will resize to full screen. If I pull down on table view to refresh then it will resize properly, so looks like Monotouch changes frame somewhere between LoadView and ViewDidAppear? – ErnestJ Jul 31 '13 at 06:01
  • You should always set your controls, arrays, etc in `ViewDidLoad` because `ViewDidLoad` is called only once. Use `ViewDidAppear` or `ViewWillAppear` to refresh/reload the data. Are you setting the `RowHeight` property of the `TableView` or you overrriden `GetHeightForRow` of the `TableView`'s source? Does the resizing occur even if you set the `AutoresizingMask` of `TableView` to `UIViewAutoresizing.None`? – Norbert Szenasi Jul 31 '13 at 10:34
  • Thank you Norbert, I've updated my original post with example which I assume should resize tableview properly? – ErnestJ Aug 06 '13 at 01:00
  • I see your answer and I totally forgot about that. Nice to see that you figured it out by yourself! – Norbert Szenasi Aug 06 '13 at 14:13
1

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.

ErnestJ
  • 167
  • 12