Anbu.Karthik
Anbu.Karthik

Reputation: 82759

UISearchbar disappears when first letter press UISearchBar field,iOS7

here my code in view controller.h

#import "AppDelegate.h"

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


@property (strong, nonatomic) UISearchDisplayController *controller;

in 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;
}

delegate method for 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];

}

Upvotes: 3

Views: 881

Answers (2)

Homam
Homam

Reputation: 5076

Try this:

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

Upvotes: 1

Retro
Retro

Reputation: 4005

try this

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

Upvotes: 1

Related Questions