ビューコントローラに2つの検索バーが表示されます。私は別のVCに同じ正確なコードを持っていて、それは正常に動作するので、それは奇妙です。(バックグラウンドの検索バーはそこにあるべきではありません)
これがスクリーンショットです:
代表者を追加しました:<UISearchBarDelegate, UISearchDisplayDelegate>
次に.hで:
@property (nonatomic,retain) IBOutlet UISearchBar *searchBar;
.mで:
@synthesize searchBar;
viewDidLoadで:
self.searchBar.frame = CGRectMake(204, 11, 107,44);
self.searchBar.delegate = self;
//customize the searchbar
UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];
[searchField setBackground:[UIImage imageNamed:@"search_panel.png"]];
[self.searchBar setTintColor:[UIColor redColor]];
UIImage *searchimg = [UIImage imageNamed:@"searchfield_bg.png"];
for (UIView *subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:searchimg];
[self.searchBar insertSubview:bg aboveSubview:subview];
[subview removeFromSuperview];
break;
}
}
[self.view addSubview:self.searchBar];
以上です。ストーリーボードビューコントローラーxibのsearchBarとは何の関係もありません。これは、viewDidLoadメソッドにプログラムで追加されます。
助けてくれてありがとう