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

uemypmqf  于 2023-03-06  发布在  iOS
关注(0)|答案(1)|浏览(212)

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

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;
        }

场景委托中的代码

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();
        }

第一视图控制器中的代码

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

oewdyzsn

oewdyzsn1#

我也尝试创建一个新项目并删除main.storyboard文件,初始化发生在AppDelegate类和SceneDelegate中,然后遇到了与您相同的问题,我修改了SceneDelegate中的代码,如下所示,它工作正常:

public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
 {
    
      Window = new UIWindow(scene as UIWindowScene);
      ...
 }

相关问题