Created
January 20, 2011 16:24
-
-
Save kwylez/788116 to your computer and use it in GitHub Desktop.
This file contains 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
// Parent UIViewControlller | |
- (void)viewWillAppear:(BOOL)animated { | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(refreshSearchBarControllerWithDepartmentCode:) | |
name:@"DepartmentCodeNotification" | |
object:nil]; | |
[super viewWillAppear:animated]; | |
} | |
- (void) refreshSearchBarControllerWithDepartmentCode:(NSNotification *)notification { | |
NSString *key; | |
NSString *trimmedSearchString; | |
for (key in [notification userInfo]) { | |
trimmedSearchString = [[[notification userInfo] valueForKey:key] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
} | |
self.searchDisplayController.searchBar.text = trimmedSearchString; | |
[self.searchDisplayController.searchBar becomeFirstResponder]; | |
[self.searchDisplayController.searchResultsTableView reloadData]; | |
} | |
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope { | |
if (selectedScope == DEPARTMENT_SCOPE_TITLE_INDEX && [[self.searchDisplayController.searchBar text] length] <= 2) { | |
DepartmentsViewController *dvController = [[DepartmentsViewController alloc] initWithNibName:@"DepartmentsView" bundle:[NSBundle mainBundle]]; | |
[self presentModalViewController:dvController animated:YES]; | |
[dvController release]; | |
} else if ([[self.searchDisplayController.searchBar text] length] >= 2) { | |
NSString *trimmedSearchString = [[self.searchDisplayController.searchBar text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
[self getEmployees:trimmedSearchString method:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:selectedScope]]; | |
[self.searchDisplayController.searchResultsTableView reloadData]; | |
} | |
} | |
//Child UIViewController | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSString *code = [self.tableView cellForRowAtIndexPath:indexPath].detailTextLabel.text; | |
NSString *description = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text; | |
NSDictionary *searchDepartmentCode = [NSDictionary dictionaryWithObjectsAndKeys: code, description, nil]; | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"DepartmentCodeNotification" | |
object:nil | |
userInfo:searchDepartmentCode]; | |
[self dismissModalViewControllerAnimated:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment