Search code examples
iosxamarinresignfirstresponder

How to resignfirstresponder touching scrollview in xamarin


Creating an iOS app with Xamarin in Visual Studio.

I have a UIViewController that contains a UITextField and a UITableView to display search results. When you type into the textfield the keyboard appears. I also do a search on a backround thread and display the results in the UITableView.

I need to hide the keyboard so that the user can scroll through the search results. How should I do this?

Thanks,


Solution

  • Under below two situations:

    1.When you finish searching in background

    2.Detect the scroll event of tableView:

    tableView.Scrolled += (sender, e) => { ViewOnScrolled(sender, e); };
    

    you can call:

    textF.ResignFirstResponder();
    

    Or

    textF.EndEditing(true);
    

    Or

    this.View.EndEditing(true);
    

    to hide the keyboard.