gpt4 book ai didi

iphone - iPhone 上的搜索栏未修复

转载 作者:行者123 更新时间:2023-11-29 04:14:29 26 4
gpt4 key购买 nike

我有两个问题:

  1. 我的 iPhone 屏幕上有一个搜索栏。当我滚动屏幕时,我的搜索栏也会滚动。我想解决这个问题或使其绝对化。
  2. 搜索不像如果我输入 A 那么我应该得到所有以字母 A 开头的单词。

我正在尝试的代码:

- (void)viewDidLoad {
[super viewDidLoad];
const NSInteger searchBarHeight = 45;
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0,
self.tableView.frame.size.width, searchBarHeight)];
searchBar.delegate = self;
self.tableView.tableHeaderView = searchBar;
[searchBar release];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Refresh"
style:UIBarButtonItemStyleBordered target:self action:@selector(onAddContact:)];
self.navigationItem.rightBarButtonItem = addButton;
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor]; // change this color
self.navigationItem.titleView = label;
label.text = NSLocalizedString(@"All Contacts", @"");

[label sizeToFit];
content = [DataGenerator wordsFromLetters];
indices = [[content valueForKey:@"headerTitle"] retain];
}

最佳答案

您需要将搜索栏与表格 View 分开。只需将搜索栏添加到 View 中,而不是将其添加到表格中。代码如下:

[self.view addSubview:searchBar];

然后添加表格 View 。

对于 UISearchDisplayController 示例,请遵循本教程: http://cocoabob.net/?p=67或者 http://blog.mugunthkumar.com/coding/iphone-tutorial-uisearchdisplaycontroller-with-nspredicate/

源代码也可用。如果您不明白,请告诉我。我有一个项目,所有这些都已经实现了。

关于iphone - iPhone 上的搜索栏未修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13909986/

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