2011-06-06 5 views
0

テーブルビューで2つのUISearchBarsを作成する必要があります。私はテーブルの上に(横に並べて)等幅の両方の両方をしたい。TableViewでUISearchBarsの幅を変更する

私はUISearchBarの2つのアウトレットを作成しました。私はそれを両方の視点に置くのが難しいと感じています。 1つの検索バーが画面の全幅に拡大されます。どのように私は2つに合うのですか?

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 4, 45)]; 
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(4, 0, 4, 45)]; 

searchBar.placeholder = @"School Name"; 
[email protected]"Zip"; 

searchBar.delegate = self; 
zipSearchBar.delegate = self; 

self.tableView.tableHeaderView= zipSearchBar; 
self.tableView.tableHeaderView= searchBar; 
searchBar.autocorrectionType = UITextAutocorrectionTypeNo; 

答えて

3

あなたがself.tableView.tableHeaderView= searchBar;を実行したときに、単にそれを再割り当てするだけです。両方の検索バーを含むビューを作成し、それをテーブルのヘッダービューに設定する必要があります。このようなもの、

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 45)]; 
zipSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(200, 0, 120, 45)]; 

searchBar.placeholder = @"School Name"; 
[email protected]"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]; 
+0

FML!私はUISearchBarの幅を変更することができないと言ったすべての記事をオンラインで奪い取った。非常に感謝@DEEPAK。 – Legolas

+0

@Deepak:http://stackoverflow.com/questions/6258001/real-time-search-in-uitableview – Legolas

+0

それを見ました。私はそこにいるとは思わない。 –

関連する問題