Bug 17714 - DidRotate in a MTD app causes first responder to get lost
Summary: DidRotate in a MTD app causes first responder to get lost
Status: RESOLVED UPSTREAM
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: 7.0.6.x
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-02-11 20:13 UTC by danmiser
Modified: 2018-04-11 06:47 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description danmiser 2014-02-11 20:13:07 UTC
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:
- If you comment out the base.DidRotate() call, it works (but Apple wants you to call the base)
- If you comment out the call to tableView.ReloadData() inside the ReloadData() method, it works (but I don't know what side effects that opens up)
- Keeping the first responder and keyboard after rotation works in non-MTD apps

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 1 Rolf Bjarne Kvinge [MSFT] 2014-02-12 05:59:25 UTC
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.
Comment 2 Alex Soto [MSFT] 2017-03-06 16:56:10 UTC
I can confirm this is still happening on latest stable, the first responder is lost as soon as device rotation happens
Comment 3 Alex Soto [MSFT] 2018-04-11 06:47:29 UTC
Closed in favor of https://github.com/migueldeicaza/MonoTouch.Dialog/issues/250