I'm attempting to store the user's input from UISearchBar and then use that string in another view controller. Here's my code:
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
JobDetailViewController *detail =[[JobDetailViewController alloc] init];
[self.navigationController pushViewController:detail animated:YES];
self.jobSearchString = self.searchBar.text;
[detail searchMethod];
NSLog(@"%@",self.jobSearchString);
}
I've stored the string in a text property that I've declared in my header file and I am then pushing to another controller and calling a method. Here's the next view where I attempt to use the string stored:
JobbyViewController *mainView = [[JobbyViewController alloc] init];
NSString *searchString = [self.searcherString stringByReplacingOccurrencesOfString:@" " withString:@"-"];
It keeps coming up as (null). Any ideas?
Create a @property
on your JobDetailViewController
and set it
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
JobDetailViewController *detail =[[JobDetailViewController alloc] init];
detail.searchString = self.searchBar.text
[self.navigationController pushViewController:detail animated:YES];
self.jobSearchString = self.searchBar.text;
[detail searchMethod];
NSLog(@"%@",self.jobSearchString);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments