2012-03-14 94 views
1

我在我的代码中使用搜索显示控制器进行搜索。但它给了一些问题。当视图是负载搜索栏框架正在走出视图,但每当我试图搜索的东西它来到我需要的适当的框架。我无法识别我的代码中的问题。我附上了可以让你更清楚问题的图片。搜索显示控制器框架

下面是搜索代码:

编译标志UISearchDisplayController委托方法

- (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]]; 
    } 
} 

enter image description here

enter image description here

请如果有人有想法如何设置搜索栏框架,为我提供一些解决方案。

感谢所有。

回答

0

感谢您查看我的问题。我已经通过编程方式使用搜索栏而不是搜索显示控制器来解决此问题。