【问题标题】:UISearchbar disappears when first letter press UISearchBar field,iOS7当第一个字母按 UISearchBar 字段时,UISearchbar 消失,iOS7
【发布时间】:2014-01-26 07:02:42
【问题描述】:

这里是我在 view controller.h 中的代码

#import "AppDelegate.h"

@interface SearchRsultsFanSideViewController : UIViewController<UISearchBarDelegate,UISearchDisplayDelegate>
{
}
@property (strong, nonatomic) IBOutlet UISearchBar *searchData;


@property (strong, nonatomic) UISearchDisplayController *controller;

在 viewcontroller.m 中

- (void)viewDidLoad
 {
   [super viewDidLoad];
  searchResults=[[NSArray alloc]init];
 self.controller = [[UISearchDisplayController alloc]initWithSearchBar:searchData contentsController:self];
    self.controller.searchResultsDataSource = self;
    self.controller.searchResultsDelegate = self;
}

UIsearchbar 的委托方法

#pragma Mark - SearchBar Delegate

- (void)filterData
{

searchResults = nil;

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [cd] %@", searchData.text];
NSArray *arrayaaa=[finalArray copy];
NSLog(@"The result Datas==%@",arrayaaa);
searchResults = [[arrayaaa filteredArrayUsingPredicate:predicate] mutableCopy];


}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

[self.searchDisplayController setActive:YES];

[self filterData];

}

【问题讨论】:

  • filterData有什么用处>?
  • 什么是self.searchDisplayController?
  • 我使用了我使用的故事板
  • 用于谓词数组的filterdata方法
  • 隐藏时你的视图框架会改变吗

标签: ios ios7 uisearchbar uisearchdisplaycontroller


【解决方案1】:

试试这个:

-(void) viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    if (self.searchDisplayController.isActive) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }
}

【讨论】:

    【解决方案2】:

    试试这个

    - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller{
        [controller.searchBar setFrame:CGRectMake(44, 0, 320 - 44, 43)];
        [self.searchDisplayController.searchResultsTableView setDelegate:self];
    }
    

    【讨论】:

    • 在这个委托上调试你的代码并检查搜索栏框架,搜索时当前设置的内容
    猜你喜欢
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多