migueldeicaza / MonoTouch.Dialog

Tools to simplify creating dialogs with the user using MonoTouch
MIT License
430 stars 211 forks source link

Fix for scrolling losing entry alignment padding #234

Closed danmiser closed 9 years ago

danmiser commented 9 years ago

using System; using MonoTouch.Dialog; using MonoTouch.UIKit; using MonoTouch.Foundation;

namespace MTDEntryElementScrollBugClassic { //1. Run (simulator or device doesn't matter) //2. Enter some data in the first entry element //3. Set focus to next entry element //4. Scroll to make the first entry element disappear off of the top //5. Scroll back to the top //EXPECTED: Right-aligned data with a padding of 40 //ACTUAL: Right-aligned data with no padding //NOTES: If you just create EntryElements (i.e. not indirectly through a custom element), the pad problem doesn't happen public class HomeScreen: DialogViewController { public HomeScreen(): base(null, true) { Root = CreateRoot(); }

    public RootElement CreateRoot()
    {           
        RootElement rootElement = new RootElement("Details");
        for (int i = 0; i < 20; i++)
        {
            var section = AddSection(i);
            rootElement.Add(section);
        }
        return rootElement;
    }

    static Section AddSection(int i)
    {
        Section section = new Section("Test" + i.ToString());
        var entryElement = new MyEntryElement("ID", "", "");
        //Use this to not have the display problem
        //var entryElement = new EntryElement("ID", "", "");
        //entryElement.TextAlignment = UITextAlignment.Right;
        section.Add(entryElement);
        return section;
    }
}

public class MyEntryElement : EntryElement
{
    public MyEntryElement(string caption, string placeholder, string value) : base(caption, placeholder, value)
    {
    }

    static NSString cellkey = new NSString ("MyEntryElement");
    protected override NSString CellKey {
        get {
            return cellkey;
        }
    }

    public override UITableViewCell GetCell(UITableView tv)
    {
        if (textField != null)
            Console.WriteLine(textField.Frame.Right);
        return base.GetCell(tv);
    }

    UITextField textField;
    protected override MonoTouch.UIKit.UITextField CreateTextField(System.Drawing.RectangleF frame)
    {
        //frame.Width -= 40;
        textField = base.CreateTextField(frame);
        textField.TextAlignment = UITextAlignment.Right;
        return textField;
    }
}

}

danmiser commented 9 years ago

This fix doesn't work well on iPads