Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the search, create a searchArray and a searchText, also you need a textfield that invokes the didChange method.</p> <p>Use this to link the textfield to the didChange method:</p> <pre><code>[self.searchTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; </code></pre> <p>Then in the didChange update the searchText and call the updateSearchArray.</p> <pre><code>-(void)textFieldDidChange:(UITextField*)textField { searchTextString = textField.text; [self updateSearchArray]; } </code></pre> <p>In the updateSearchArray you compare go through the original array (dummyArray) and if the name is included in the search then add it to the searchArray.</p> <pre><code>-(void)updateSearchArray { if (searchTextString.length != 0) { searchArray = [NSMutableArray array]; for ( NSDictionary* item in dummyArray ) { if ([[[item objectForKey:@"name"] lowercaseString] rangeOfString:[searchTextString lowercaseString]].location != NSNotFound) { [searchArray addObject:item]; } } } else { searchArray = dummyArray; } [self.tableView reloadData]; } </code></pre> <hr> <p>Use the searchArray in the tableview methods where you now use the dummyArray.</p> <p>Updated tableview methods</p> <pre><code>#pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [searchArray count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.textLabel.text = [[searchArray objectAtIndex:indexPath.row] objectForKey:@"name"]; return cell; } </code></pre> <p>Also, you need to call a reloadData after adding all the data to the array. And added the updateSearchArray method</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [self setupData]; [self updateSearchArray]; [self.tableView reloadData]; } </code></pre> <hr> <hr> <p><strong>To make it easier to implement this I have made a sample project. You can download it here:</strong> <a href="http://www.rolandkeesom.com/SearchExample.zip" rel="nofollow">http://www.rolandkeesom.com/SearchExample.zip</a></p> <hr> <hr>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload