UISearchBar 在横向模式下没有响应,但在 iPad 上的纵向模式下则正常

发布于 2024-11-07 15:48:26 字数 1067 浏览 4 评论 0原文

我正在开发的应用程序中有一个关于 UISearchBar 的错误。

使用代码:

    int width = 250;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(768 - width - indent, companySelectionButton.frame.origin.y + (companySelectionButton.frame.size.height - 44)/2, width, 44)];
[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];
[searchBar setPlaceholder:[Globals localisedString:@"Search by Code or Name"]];
[searchBar setAutocorrectionType:UITextAutocorrectionTypeNo];
[searchBar setDelegate:self];
[self.view addSubview:searchBar];
[searchBar release];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];

搜索栏在两个方向上都位于我想要的位置,但它不会响应横向点击并成为第一响应者/显示键盘。

我尝试注释掉以下几行,看看是否有帮助,但没有解决问题:

[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];

[[searchBar.subviews objectAtIndex:0] removeFromSuperview];

还有其他人有类似的问题吗?

提前致谢:)

编辑

注释掉 [searchBar setDelegate:nil];搜索栏能够成为所有方向的第一响应者。但当然我需要一个代表才能使用搜索栏!有什么想法吗???会继续玩,也许我缺少一些委托方法?

I have a bug in an app I'm working on regarding a UISearchBar.

Using the code:

    int width = 250;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(768 - width - indent, companySelectionButton.frame.origin.y + (companySelectionButton.frame.size.height - 44)/2, width, 44)];
[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];
[searchBar setPlaceholder:[Globals localisedString:@"Search by Code or Name"]];
[searchBar setAutocorrectionType:UITextAutocorrectionTypeNo];
[searchBar setDelegate:self];
[self.view addSubview:searchBar];
[searchBar release];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];

The search bar is in the position I want in both orientations, but it won't respond to taps in landscape and become first responder/show the keyboard.

I've tried commenting out the following lines to see if it helps but it doesn't fix it:

[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];

[[searchBar.subviews objectAtIndex:0] removeFromSuperview];

Anyone else had a similar issue?

Thanks in advance :)

EDIT

After commenting out [searchBar setDelegate:nil]; the search bar is able to become first responder in all orientations. But of course I need a delegate to be able to use the searchbar! Any ideas??? Will continue to have a play, perhaps I'm missing some delegate method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稍尽春風 2024-11-14 15:48:26

在 willRotateToInterfaceOrientation 中重新绘制搜索栏的框架可以解决该问题。

Redrawing the frame of the searchbar in willRotateToInterfaceOrientation fixes the issue.

じее 2024-11-14 15:48:26

抱歉大家,我发现我不小心在 searchBarTextDidBeginEditing 委托方法中做了一些奇怪的事情,如果设备处于横向状态,则该方法将搜索栏作为第一响应者。

这个问题对任何人都没有用,我应该删除它吗?

Sorry everyone, I discovered that I was accidentally doing something strange in my searchBarTextDidBeginEditing delegate method that resigned the searchbar as first responder if the device was in landscape.

This question is of no use to any one, should I delete it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文