我需要在我的 tableView 中创建两个 UISearchBar。我希望它们在 table 顶部的宽度相等(并排)。
我已经创建了 UISearchBar 的两个导出,并为它们创建了 property 和 de alloc。我发现很难将它们都放在(我的意思是适合) View 中。我只有一个搜索栏扩展到屏幕的全宽。我怎么装两个?
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 4, 45)];
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(4, 0, 4, 45)];
searchBar.placeholder = @"School Name";
zipSearchBar.placeholder=@"Zip";
searchBar.delegate = self;
zipSearchBar.delegate = self;
self.tableView.tableHeaderView= zipSearchBar;
self.tableView.tableHeaderView= searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
最佳答案
当您执行 self.tableView.tableHeaderView= searchBar;
时,您只是重新分配它。您必须构建一个包含两个搜索栏的 View ,然后将其设置为表的标题 View 。像这样,
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(200, 0, 120, 45)];
searchBar.placeholder = @"School Name";
zipSearchBar.placeholder=@"Zip";
searchBar.delegate = self;
zipSearchBar.delegate = self;
UIView * comboView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
[comboView addSubview:searchBar];
[comboView addSubview:zipSearchBar];
self.tableView.tableHeaderView= comboView;
[comboView release];
关于iphone - 更改 TableView 上 UISearchBar 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6253827/