2014-01-08 48 views
3

這裏我的代碼鑑於或者Controller.h的UISearchBar消失時,第一個字母按領域的UISearchBar,iOS7

#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]; 

} 
+0

有什麼用篩選數據的>? –

+0

什麼是self.searchDisplayController? – Tendulkar

+0

我使用了故事板這是你用的 –

回答

1

試試這個

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

顯示沒有更改兄弟 –

+0

在此代理處調試您的代碼並檢查搜索欄框架,搜索時當前設置的是什麼 – Retro

1

試試這個:

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