I am using search display controller in my code for searching. But it is giving some problem. When view is load search bar frame is going out of the view but whenever I am trying to search something it comes in its proper frame which I need. I am unable to recognize the problem in my code. I have attached the images which will make you more clear about the problem.
Here is the code for searching:
pragma mark UISearchDisplayController Delegate Methods
- (void)handleSearchForTerm:(NSString *)searchTerm
{
searchbar.frame = CGRectMake(391, 28, 586, 44);
[self setSavedSearchTerm:searchTerm];
if ([self searchResults] == nil)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[self setSearchResults:array];
}
[[self searchResults] removeAllObjects];
if ([[self savedSearchTerm] length] != 0)
{
int i = 0;
for (NSString *currentString in [[self contentsList]valueForKey:@"name"])
{
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
{
[[self searchResults] addObject:currentString];
[[self searchResults] addObject:[[[self contentsList]objectAtIndex:i] objectForKey:@"id"]];
[[self searchResults] addObject:[[[self contentsList]objectAtIndex:i] objectForKey:@"category"]];
NSString *searchcategory = [[[self contentsList]objectAtIndex:i] objectForKey:@"category"];
[[self searchResults] addObject:[[[self contentsList]objectAtIndex:i] objectForKey:@"flavour"]];
[[self searchResults] addObject:[[[self contentsList]objectAtIndex:i] objectForKey:@"price"]];
[[self searchResults] addObject:[[[self contentsList]objectAtIndex:i] objectForKey:@"image"]];
}
i++;
}
}
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
searchbar.frame = CGRectMake(391, 28, 586, 44);
[self handleSearchForTerm:searchString];
return YES;
}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
searchbar.frame = CGRectMake(391, 28, 586, 44);
[self setSearchResults:nil];
[self setSavedSearchTerm:nil];
[[self itemstable_ipad]reloadData];
}
-(void)searchmethod
{
searchbar.frame = CGRectMake(391, 28, 586, 44);
[self setContentsList:categoryarray_ipad];
if ([self savedSearchTerm])
{
[[[self searchDisplayController] searchBar] setText:[self savedSearchTerm]];
}
}


please if anyone has idea how to set search bar frame, provide me some solution.
Thanks to all.
Thanks for viewing my problem. I have resolved this problem by using searchbar programmatically instead of search display controller.