【问题标题】:UISearchBar not responding in landscape, but fine in portrait on iPadUISearchBar 在横向没有响应,但在 iPad 上的纵向正常
【发布时间】:2011-05-16 11:50:51
【问题描述】:

我正在开发的应用中有一个关于 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]后;搜索栏能够成为所有方向的第一响应者。但当然我需要一个代表才能使用搜索栏!有任何想法吗???会继续玩,也许我错过了一些委托方法?

【问题讨论】:

    标签: iphone ipad uisearchbar first-responder


    【解决方案1】:

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

    【讨论】:

    • 你能在改变搜索栏的框架大小后告诉你发生了什么吗?/?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多