搜索显示控制器框架

时间:2012-03-14 06:29:40

标签: iphone

我在我的代码中使用搜索显示控制器进行搜索。但它提出了一些问题。当视图是加载时,搜索栏框架将离开视图,但每当我尝试搜索某些内容时,它都会进入我需要的正确框架。我无法识别代码中的问题。我附上的图片会让你更清楚这个问题。

以下是搜索代码:

pragma mark 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

如果有人知道如何设置搜索栏框架,请给我一些解决方案。

感谢所有人。

1 个答案:

答案 0 :(得分:0)

感谢您查看我的问题。我通过编程方式而不是搜索显示控制器来解决这个问题。