migueldeicaza / MonoTouch.Dialog

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

[Bugzilla] DidRotate in a MTD app causes first responder to get lost #250

Open dalexsoto opened 6 years ago

dalexsoto commented 6 years ago

From https://bugzilla.xamarin.com/show_bug.cgi?id=17714:

Moved from discussion here: https://forums.xamarin.com/discussion/13341/restore-focus-after-rotate#latest

  1. Run this code.
  2. Select either the ID or Name control so that it has focus and the keyboard appears
  3. Rotate the device/simulator

//expected: Device to rotate and the first responder to remain as is with the keyboard selected //actual: The device rotates, but the first responder is lost

Notes:

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

namespace MTDRotate
{
    public class HomeScreen: DialogViewController
    {
        public HomeScreen(): base(null, true)
        {
            Title = "Rotate Focus";
            Root = CreateRoot();
        }

        public RootElement CreateRoot()
        {           
            RootElement rootElement = new RootElement("Details");
            Section section = new Section("Test");
            section.Add(new EntryElement("ID", "", ""));
            section.Add(new EntryElement("Name", "", ""));
            rootElement.Add(section);
            return rootElement;
        }

        public override void DidRotate(MonoTouch.UIKit.UIInterfaceOrientation fromInterfaceOrientation)
        {
            base.DidRotate(fromInterfaceOrientation);
        }
    }
}

Comment from Rolf:

Apparently ReloadData should resign the first responder:

http://stackoverflow.com/questions/6409370/uitableview-reloaddata-resigns-first-responder

However we seem to need ReloadData to resize cells:

https://github.com/migueldeicaza/MonoTouch.Dialog/commit/b55b51d1668adb9f7ca90c68e2526b977c18f4bd

I'm not sure how to best solve this situation.