Last active
August 21, 2018 20:05
-
-
Save patelrohan/4352890 to your computer and use it in GitHub Desktop.
Put UISearchBar in Navigation Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.title = @"Literature"; | |
if (searchText.length > 0) { | |
[searchBar setShowsCancelButton:YES]; | |
searchBar.text = searchText; | |
[self searchLiteraturesWithName:searchText]; | |
} | |
[self.navigationController.navigationBar setTintColor:[UIColor primaryBarColor]]; | |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] | |
initWithTitle:@"Categories" | |
style:UIBarButtonItemStylePlain | |
target:self | |
action:@selector(showList:)]; | |
//Mark: Original Snippet commented | |
/* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 0.0)]; | |
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar]; | |
searchBar.placeholder = @"Search Files"; | |
searchBar.delegate = self; | |
recentSearchesController = [[SearchViewController alloc] | |
initWithStyle:UITableViewStylePlain];*/ | |
searchBar.delegate = self; | |
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 44.0)]; | |
searchBar.placeholder = @"Search Files"; | |
searchBar.userInteractionEnabled=YES; | |
//searchBar.tintColor=[UIColor clearColor]; | |
UIView *searchBarContainer = [[UIView alloc] initWithFrame:searchBar.frame]; | |
[searchBarContainer addSubview:searchBar]; | |
UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc] initWithCustomView:searchBarContainer]; | |
NSMutableArray *items= [[NSMutableArray alloc]initWithCapacity:2]; | |
UIBarButtonItem *filter= [[UIBarButtonItem alloc]initWithTitle:@"+" style:UIBarButtonItemStylePlain target:self action:@selector(filterClick:)]; | |
[items addObject:filter]; | |
[items addObject:searchBarItem]; | |
self.navigationItem.rightBarButtonItems=items; | |
recentSearchesController = [[SearchViewController alloc] | |
initWithStyle:UITableViewStylePlain]; | |
//Mark : : Add finish | |
// Literature* root = [[[LiteratureFetcher alloc] init] rootLiterature]; | |
// [self printFolders:root]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment