gpt4 book ai didi

objective-c - UITextField 拒绝允许用户输入

转载 作者:行者123 更新时间:2023-12-01 18:26:04 24 4
gpt4 key购买 nike

我在 Interface Builder 中设置了一个 UITextField 并将其与属性 self.nameField 连接起来。我的问题是,点击它什么也没做——用户不能输入任何文本;甚至没有光标。如果我添加 becomeFirstResponder,那么键盘会自动显示。我想要的是当且仅当用户点击该字段以输入文本时才显示键盘。

涉及的方法如下:

-(void)displayOptOutScreen
{
if (!self.nameField)
{
self.nameField=[[UITextField alloc] init];
}
self.nameField.hidden=NO;
self.nameField.delegate = self;
self.nameField.returnKeyType = UIReturnKeyDone;
[self textFieldShouldReturn:self.nameField];
[self.textView resignFirstResponder]; //This is a UITextView, created programmatically
//[self.nameField becomeFirstResponder]; //Keyboard automatically displays.
}

对于它的值(value),有一个 UIButton 也不接受触摸。 UITextView 可以毫无问题地接受文本。

这是一个选项卡式应用程序。在阅读了其他 Stack Overflow 问题后,我尝试将以下几行的各种组合添加到应用程序委托(delegate)中:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[GHHaikuViewController alloc] initWithNibName:@"GHHaikuViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

但是根据我包含或不包含的行,我会遇到各种错误,并且最终没有任何效果。 ( UITextField 所在的 View Controller 不是 GHHaikuViewController 而是 GHComposeViewController ,但是当我尝试使用它时出现错误。)

关于我做错了什么有什么想法吗?

编辑: 这是界面生成器设置的屏幕截图。抱歉,他们分手了——我正在开发 MacBook Air 11"。

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

进一步编辑: 这是我在调试提示符下输入 po [[[[UIApplication sharedApplication] delegate] window] recursiveDescription] 时的输出。
(id) $1 = 0x0ad4bb80 <UIWindow: 0xad48ac0; frame = (0 0; 320 480); autoresize = W+H; layer = <UIWindowLayer: 0xad44010>>
| <UILayoutContainerView: 0x9e74450; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x9e74510>>
| | <UITransitionView: 0xaa46f80; frame = (0 0; 320 431); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xaa47050>>
| | | <UIViewControllerWrapperView: 0x9e90760; frame = (0 20; 320 411); autoresize = W+H; layer = <CALayer: 0x9e907c0>>
| | | | <UIView: 0x9e8c870; frame = (0 0; 320 411); autoresize = W+H; gestureRecognizers = <NSArray: 0x9e8bbd0>; layer = <CALayer: 0x9e8c8d0>>
| | | | | <UIImageView: 0x9e8c790; frame = (0 0; 320 411); clipsToBounds = YES; opaque = NO; autoresize = TM+BM; layer = <CALayer: 0x9e8c7f0>>
| | | | | <UITextField: 0x9e82610; frame = (40 189; 240 30); text = ''; clipsToBounds = YES; opaque = NO; autoresize = TM+BM; gestureRecognizers = <NSArray: 0x9e6ea90>; layer = <CALayer: 0x9e83720>>
| | | | | | <UITextFieldRoundedRectBackgroundView: 0x9e73ac0; frame = (0 0; 240 30); userInteractionEnabled = NO; layer = <CALayer: 0x9e73b80>>
| | | | | | | <UIImageView: 0x9e73cd0; frame = (0 0; 8 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9e73d30>>
| | | | | | | <UIImageView: 0x9e73d80; frame = (8 0; 224 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9e73de0>>
| | | | | | | <UIImageView: 0x9e73e10; frame = (232 0; 8 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9e73e70>>
| | | | | | <UITextFieldLabel: 0x9e8afa0; frame = (7 7; 226 15); text = 'Name (optional)'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9e8af20>>
| | | | | <UIButton: 0xad6fb00; frame = (236 221; 44 44); clipsToBounds = YES; opaque = NO; autoresize = TM+BM; layer = <CALayer: 0xad6fbf0>>
| | | | | | <UIImageView: 0x9e921c0; frame = (14 14; 16 16); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9e922d0>>
| | | | | | <UIButtonLabel: 0x9e8a6f0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9e8a790>>
| | | | | <UITextView: 0xa3de800; frame = (20 90; 300 480); text = '
I hope to update the May...'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x9e72ef0>; animations = { transition=<CATransition: 0x9e8eea0>; }; layer = <CALayer: 0x9e5d770>; contentOffset: {0, 0}>
| | | | | | <UIWebDocumentView: 0xa3dec00; frame = (0 0; 300 188); text = '
I hope to update the May...'; opaque = NO; userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x9e8d5a0>; layer = <UIWebLayer: 0x9e8d220>>
| | | | | | | <TileHostLayer: 0x9e8d2b0> (layer)
| | | | | | | | <TileLayer: 0x9e90fb0> (layer)
| | <UITabBar: 0xad41b80; frame = (0 431; 320 49); autoresize = W+TM; layer = <CALayer: 0xad41c70>>
| | | <_UITabBarBackgroundView: 0xad47950; frame = (0 0; 320 49); opaque = NO; autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0xad47a00>>
| | | <UITabBarButton: 0xad42ff0; frame = (2 1; 76 48); opaque = NO; layer = <CALayer: 0xad453e0>>
| | | | <UITabBarSwappableImageView: 0xad45670; frame = (14 2; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xad45740>>
| | | | <UITabBarButtonLabel: 0xad42410; frame = (24 34; 28 13); text = 'Home'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xad42500>>
| | | <UITabBarButton: 0xad46b10; frame = (82 1; 76 48); opaque = NO; layer = <CALayer: 0xad46460>>
| | | | <UITabBarSelectionIndicatorView: 0xad5cf90; frame = (0 2; 76 44); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xad5d2f0>>
| | | | <UITabBarSwappableImageView: 0xad46490; frame = (14 2; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xad46510>>
| | | | <UITabBarButtonLabel: 0xad46790; frame = (15 34; 46 13); text = 'Compose'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xad40650>>
| | | <UITabBarButton: 0xad46630; frame = (162 1; 76 48); opaque = NO; layer = <CALayer: 0xad47080>>
| | | | <UITabBarButtonLabel: 0xad46df0; frame = (29 34; 19 13); text = 'Buy'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xad466f0>>
| | | <UITabBarButton: 0xad47270; frame = (242 1; 76 48); opaque = NO; layer = <CALayer: 0xad47770>>
| | | | <UITabBarButtonLabel: 0xad47330; frame = (15 34; 47 13); text = 'Feedback'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xad473d0>>
| | | <UIImageView: 0xad48130; frame = (0 -3; 320 3); opaque = NO; autoresize = W+BM; userInteractionEnabled = NO; layer = <CALayer: 0xad48190>>
(lldb)

最佳答案

假设您正确处理了 UIControls(例如,将所有 userInteractionEnabled 属性设置为 YES),这听起来好像您在 UIControls 之上设置了一个不可见的 UIView。

一旦您的应用程序在模拟器中运行,您可以通过暂停应用程序(使用代码下的小暂停按钮)并在调试提示符中键入以下命令来手动检查:

po [[[[UIApplication sharedApplication] delegate] window] recursiveDescription]

这将打印出 UIWindow 的描述和 全部 的 subview 。您可以以某种方式检查您的 UIControls 顶部是否有 UIView。

关于objective-c - UITextField 拒绝允许用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13801919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com