单击 UITextView Xamarin.IOS 时不显示键盘

问题描述 投票:0回答:0

我有一个通过c#代码初始化的xamarin项目(我删除了main.storyboard文件),初始化发生在appDelegate类和SceneDelegate中,该项目包含选项卡。 应用程序启动没有错误,所有控制器都显示正确,但是当你点击 UITextView 时,键盘没有出现,虽然 textView 本身是活动的并且它上面的光标闪烁

AppDelegate 中的代码

        public bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
        {
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            var tabBar = new UITabBarController();

            var firstFirstController = new FirstViewController();

            tabBar.ViewControllers = new UIViewController[]
            {
                firstFirstController
            };

            Window.RootViewController = tabBar;
            Window.MakeKeyAndVisible();

            return true;
        }

SceneDelegate 中的代码

        public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
        {
            var windowScence = new UIWindowScene(session, connectionOptions);
            Window = new UIWindow(windowScence);

            var tabBar = storyboard.InstantiateViewController("tabBar") as UITabBarController;

            var firstFirstController = storyboard.InstantiateViewController("firstViewController") as FirstViewController;
            firstFirstController.lb.Text = "BYE";

            tabBar.ViewControllers = new UIViewController[]
            {
                firstFirstController
            };

            Window.RootViewController = tabBar;
            Window.MakeKeyAndVisible();
        }

FirstViewController 中的代码

    public partial class FirstViewController : UIViewController
    {
        public UILabel lb;
        public UITextView tb; 


        public FirstViewController (IntPtr handle) : base (handle)
        {
            lb = new UILabel();
            lb.Frame = new CoreGraphics.CGRect(100, 100, 100, 40);
            lb.TextColor = UIColor.Black;
            lb.Text = "HELLO";

            tb = new UITextView(new CoreGraphics.CGRect(200, 200, 100, 40));
            tb.BackgroundColor = UIColor.Black;
            tb.Started += Tb_Started;
        }

        private void Tb_Started(object sender, EventArgs e)
        {
            tb.BecomeFirstResponder();
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            // Perform any additional setup after loading the view, typically from a nib.

            View.AddSubviews(lb, tb);
        }

        public override void DidReceiveMemoryWarning ()
        {
            base.DidReceiveMemoryWarning ();
            // Release any cached data, images, etc that aren't in use.
        }
    }

我正在公开 textView.UserInteractionEnabled = true 尝试从 tabBar 开始调用 becomeFirstResponder

c# xamarin xamarin.forms xamarin.ios uikeyboard
© www.soinside.com 2019 - 2024. All rights reserved.