I have UISearchBar in my app. I set it as table header view. When text begin editing I want to set search bar as subview of my viewController. Search bar adding to viewController's view correctly, but it's frame is incorrect. This is my code:
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
UITableView *tableView = ((UITableView *)[((SectionViewController *)sharedInstance.currentViewController).view viewWithTag:1111]);
[tableView reloadData];
if([searchBar.text isEqualToString:@"Filter..."])
{
searchBar.text = @"";
for(UIView *subView in searchBar.subviews){
if([subView isKindOfClass:UITextField.class]){
[(UITextField*)subView setTextColor:[UIColor blackColor]];
}
}
}
[((SectionViewController *)sharedInstance.currentViewController).view addSubview:searchBar];
[searchBar setFrame:CGRectMake(0, 20, 320, 38)];
[((SectionViewController *)sharedInstance.currentViewController).navigationController setNavigationBarHidden:YES animated:YES];
[searchBar setShowsCancelButton:YES animated:YES];
}
I want to set frame (0, 20, 320, 38), but I get (0, 0, 320, 38). Also, initial frame of searchBar is (0, 0, 320. 38). Please, tell me why I get this?