iOS7中的UISearchBar和UITableView出现问题

iOS7中的UISearchBar和UITableView出现问题,uitableview,ios7,uisearchbar,overlap,Uitableview,Ios7,Uisearchbar,Overlap,我有一个在iOS6中运行良好的应用程序。它有一个带有搜索栏的表视图。当我在iOS7中运行它时,我遇到了以下问题: 正如您在上图中看到的,搜索结果显示在错误的位置,它们与搜索控件重叠,您知道如何解决这个问题吗 第一个图像显示搜索控件,搜索结果应该显示在第一个图像中我用红色标记的位置 谢谢-费尔南多 嗯,我做了一些改变,但还是不太好: -(void)searchDisplayController:(UISearchDisplayController *)controller didShowSea

我有一个在iOS6中运行良好的应用程序。它有一个带有搜索栏的表视图。当我在iOS7中运行它时,我遇到了以下问题:

正如您在上图中看到的,搜索结果显示在错误的位置,它们与搜索控件重叠,您知道如何解决这个问题吗

第一个图像显示搜索控件,搜索结果应该显示在第一个图像中我用红色标记的位置

谢谢-费尔南多

嗯,我做了一些改变,但还是不太好:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
       if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
            // The tableView the search tableView replaces
            CGRect f = self.searchFavoriteListTable.frame;
            CGRect f1 = tableView.frame;

            //CGRect s = self.searchDisplayController.searchBar.frame;
            CGRect updatedFrame = CGRectMake(f1.origin.x,
                                             f.origin.y + 45,
                                             f1.size.width,
                                             f1.size.height - 45);

            tableView.frame = updatedFrame;
        }
}
我想删除的是最后一张图片中的红色部分。。。它与其他视图重叠


第一步,创建具有通用格式和通用框架的搜索栏

UISearchBar *mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[mySearchBar sizeToFit]; // if you give it CGRectZero and sizeToFit, it will shown exactly end of the your navigationBar.

mySearchBar.tintColor = [UIColor whiteColor];
mySearchBar.placeholder = @"Search Music";
mySearchBar.showsScopeBar = NO;
mySearchDisplayController *mySearchDisplay = [[mySearchDisplayController alloc] mySearchBar contentsController:self];
然后创建一个新的类类型“UISearchDisplayController”作为名称“mySearchDisplayController”,如您所见,我们应该在其中合并搜索栏3行。别忘了像这样在新类中实现UITableView协议

@interface mySearchDisplayController : UISearchDisplayController <UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource>
最后一步,您应该在tableview中标识搜索栏的新帧端

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSInteger)scope
{
        [self.filteredSearchResults removeAllObjects]; // First clear the filtered array.
            for(NSDictionary *searchResult in // your search array)
            {
                NSString *searchableString = [NSString stringWithFormat:@"%@ %@", [searchResult objectForKey:@"//your search key"]];
                NSRange stringRange = [searchableString rangeOfString:searchText options:NSCaseInsensitiveSearch];
            }
    }
    [self.searchResultsTableView reloadData];

    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat screenHeight = screenSize.height;
    CGRect frame = self.searchResultsTableView.frame;

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
    {
        frame.size.height = screenHeight-64.0f;
    }
    else
    {
        frame.size.height = screenHeight-44.0f;
    }
    self.searchResultsTableView.frame = frame;
}
-(void)filterContentForSearchText:(NSString*)搜索文本范围:(NSInteger)范围
{
[self.filteredSearchResults removeAllObjects];//首先清除已筛选的数组。
for(NSDictionary*搜索结果在//您的搜索数组中)
{
NSString*searchableString=[NSString stringWithFormat:@“%@%@,[searchResult objectForKey:@”//您的搜索键]];
NSRange stringRange=[searchableString rangeOfString:searchText选项:NSCaseInsensitiveSearch];
}
}
[self.searchResultsTableView重新加载数据];
CGRect屏幕绑定=[[UIScreen mainScreen]边界];
CGSize screenSize=screensbound.size;
CGFloat屏幕高度=屏幕尺寸.height;
CGRect frame=self.searchResultsTableView.frame;

如果(floor(NSFoundationVersionNumber)第一步,创建一个具有通用格式和通用框架的搜索栏

UISearchBar *mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[mySearchBar sizeToFit]; // if you give it CGRectZero and sizeToFit, it will shown exactly end of the your navigationBar.

mySearchBar.tintColor = [UIColor whiteColor];
mySearchBar.placeholder = @"Search Music";
mySearchBar.showsScopeBar = NO;
mySearchDisplayController *mySearchDisplay = [[mySearchDisplayController alloc] mySearchBar contentsController:self];
然后创建一个新的类类型“UISearchDisplayController”作为名称“mySearchDisplayController”,如您所见,我们应该在其中合并搜索栏3行

@interface mySearchDisplayController : UISearchDisplayController <UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource>
最后一步,您应该在tableview中标识搜索栏的新帧端

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSInteger)scope
{
        [self.filteredSearchResults removeAllObjects]; // First clear the filtered array.
            for(NSDictionary *searchResult in // your search array)
            {
                NSString *searchableString = [NSString stringWithFormat:@"%@ %@", [searchResult objectForKey:@"//your search key"]];
                NSRange stringRange = [searchableString rangeOfString:searchText options:NSCaseInsensitiveSearch];
            }
    }
    [self.searchResultsTableView reloadData];

    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat screenHeight = screenSize.height;
    CGRect frame = self.searchResultsTableView.frame;

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
    {
        frame.size.height = screenHeight-64.0f;
    }
    else
    {
        frame.size.height = screenHeight-44.0f;
    }
    self.searchResultsTableView.frame = frame;
}
-(void)filterContentForSearchText:(NSString*)搜索文本范围:(NSInteger)范围
{
[self.filteredSearchResults removeAllObjects];//首先清除已筛选的数组。
for(NSDictionary*搜索结果在//您的搜索数组中)
{
NSString*searchableString=[NSString stringWithFormat:@“%@%@,[searchResult objectForKey:@”//您的搜索键]];
NSRange stringRange=[searchableString rangeOfString:searchText选项:NSCaseInsensitiveSearch];
}
}
[self.searchResultsTableView重新加载数据];
CGRect屏幕绑定=[[UIScreen mainScreen]边界];
CGSize screenSize=screensbound.size;
CGFloat屏幕高度=屏幕尺寸.height;
CGRect frame=self.searchResultsTableView.frame;
if(楼层(NSFoundationVersionNumber)