Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help understanding how to use UISearchBar with Core Data
    primarykey
    data
    text
    <p>I have an iPad app (XCode 4.6, iOS 6.2, ARC and Storyboards). I have a UITableView that contains prototype cells, with two labels (lName and lPhone). I have filled a NSArray with the results of the Core Data store. I copied the code from a <a href="http://www.iphonesdkarticles.com/2009/01/uitableview-searching-table-view.html" rel="nofollow">sample</a>, and am lost! I have two fields I am looking for: name and phone number. I want to be able to search on either one. I tried using the UISearchBar Controller, but the results span the entire window, which is not acceptable. So, I'm trying to do this without the controller. I want the search to filter the shown entries in the UITableView, which this bit of code is supposed to do. </p> <p>When I do the MR_findAll (MagicalRecord), I get all of the attributes in the Core Data store. This is where I'm lost - how do I get the two attributes out of the array and into the NSMutableArray <em>allTableData</em>, or is it even necesary in this case? </p> <p>This is my code, so far:</p> <pre><code>NSArray *allDataArray = [ClientInfo MR_findAll]; // move objects from Core Data store to NSMutablearray [allTableData addObjectsFromArray:allDataArray]; if(text.length == 0) { isFiltered = FALSE; } else { isFiltered = true; filteredTableData = [[NSMutableArray alloc] init]; for (ClientCell* client in allTableData) { NSRange nameRange = [client.lName.text rangeOfString:text options:NSCaseInsensitiveSearch]; NSRange phoneRange = [client.lPhone.text rangeOfString:text options:NSCaseInsensitiveSearch]; if(nameRange.location != NSNotFound || phoneRange.location != NSNotFound) { [filteredTableData addObject:client]; } } } </code></pre> <p>I also don't understand <em>how</em> the NSRange is going to match against the two fields I'm looking for. I'm really confused here... help is greatly appreciated!</p>
    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. 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