I am new to coding and I’ve been making great progress… until now! I’ve been setting up an application for the iPhone but I’ve run into a wall.
I’m trying to send the searchString from my HomeViewController‘s UISearchBar to my tableViewController‘s UISearchBar, and then I want my TableViewController‘s UISearchBar to automatically execute a search based upon the initial searchString, thus populating the TableViewController‘s table with a filtered array.
When I use the home view’s searchBar, it does push the application to the table view, however, the database’s array isn’t filtered. The table view does have a functional UISearchBar that can filter my array based upon various searchStrings that I feed it.
I’ve tried many things based upon examples I’ve found through google, but nothing seems to work.
Here is my relevant code. (I’ve left out a bit of code that I think is irrelevant to the problem at hand).
HOME VIEW CONTROLLER
@interface HomeViewController : UIViewController <UISearchBarDelegate>
{
NSString *pushedSearchString;
UISearchBar *homeSearchBar;
}
@property (strong) NSString *pushedSearchString;
@property (nonatomic,strong) IBOutlet UISearchBar *homeSearchBar;
...
...
...
@implementation HomeViewController
@synthesize pushedSearchString, homeSearchBar;
- (void)updateSearchString:(NSString*)aSearchString
{
pushedSearchString = [[NSString alloc] initWithString:aSearchString];
}
- (void)searchBarButtonClicked:(UISearchBar *)searchBar
{
[self updateSearchString:searchBar.text];
[searchBar resignFirstResponder];
TableViewController *tableViewController = [self.storyboard insantiateViewControllerWithIdentifier:@"table"];
table.title = @"Results";
[self.navigationController pushViewController:table animated:YES];
}
…
…
…
My TableViewController looks similar although it has slightly different variables. I’ve tried manipulating code inside the -(void)viewWillAppear:(BOOL)animated method, as I’ve seen via other posts, but nothing worked.
I would greatly appreciate any help I can get – thanks for reading this and thanks for your time!
Declare the property for a NSString in Tableviewcontroller.And synthesize it in .m file.And make the below change in your homeviewcontroller method.