Search Results

Search found 39 results on 2 pages for 'uisearchdisplaycontroller'.

Page 1/2 | 1 2  | Next Page >

  • UISearchDisplayController not working when created in code??

    - by Nick Bedford
    I'm working on a tab bar application and one of the tabs has a UISearchDisplayController hooked up to a UISearchBar. It's all connected up in the NIB and is working. When I tap the search bar, the Scope and Cancel buttons fly in etc, and the search delegate updates the results table correctly. However, I'm trying to implement the same code in the viewDidLoad message instead of the NIB, however when I delete the search display controller from the NIB and uncomment my code to create the same controller in the function, it doesn't work. It's as if there's some fundamental connection not being made so that all my search delegate functionality isn't being called. Here's my working NIB version of the Search Display Controller. It's hooked up to the search bar, the UINavigationController subclass (MASearchController) and the root view of that is hooked up as the searchContentsController. Now this is what you would expect to do in code to create the same, right? What I'm doing is leaving the UISearchBar in the NIB to eliminate one piece of the puzzle at a time in code. // [MASearchController viewDidLoad] UISearchDisplayController *searchController = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:[[self viewControllers] objectAtIndex:0]] autorelease]; [searchController setDelegate:self]; [searchController setSearchResultsDelegate:self]; [searchController setSearchResultsDataSource:self]; I've checked all objects at run time and they all check out. Essentially I've deleted the search display controller from the NIB and then put in the code to create it in the viewDidLoad message. Why would this not work? The search keyboard comes up but none of my search and button animation functionality work???

    Read the article

  • Why won't my UISearchDisplayController fire the didSelectRowAtIndexPath moethod?

    - by John Wells
    I am having an odd problem when searching a UITableView using a UISearchDisplayController. The UITableViewController is a subclass of another UITableViewController with a working didSelectRowAtIndexPath method. Without searching the controller handles selections fine, sending the superclass a didSelectRowAtIndexPath call, but if I select a cell when searching the superclass receives nothing but the cell is highlighted. Below is the code from my subclass. @implementation AdvancedViewController @synthesize searchDisplayController, dict, filteredList; - (void)viewDidLoad { [super viewDidLoad]; // Programmatically set up search bar UISearchBar *mySearchBar = [[UISearchBar alloc] init]; mySearchBar.delegate = self; [mySearchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [mySearchBar sizeToFit]; self.tableView.tableHeaderView = mySearchBar; // Programmatically set up search display controller searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self]; [self setSearchDisplayController:searchDisplayController]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; // Parse data from server NSData * jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]]; NSArray * items = [[NSArray alloc] initWithArray:[[CJSONDeserializer deserializer] deserializeAsArray:jsonData error:nil]]; // Init variables dict = [[NSMutableDictionary alloc] init]; listIndex = [[NSMutableArray alloc] init]; fullList = [[NSMutableArray alloc] init]; filteredList = [[NSMutableArray alloc] init]; // Get each item and format it for the UI for(NSMutableArray * item in items) { // Get the first letter NSString * firstKey = [[[item objectAtIndex:0] substringWithRange:NSMakeRange(0,1)] uppercaseString]; // Put symbols and numbers in the same section if ([[firstKey stringByTrimmingCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] isEqualToString:@""]) firstKey = @"#"; // If there isn't a section with this key if (![listIndex containsObject:firstKey]) { // Add the key to the index for faster access (because it's already sorted) [listIndex addObject:firstKey]; // Add the key to the unordered dictionary [dict setObject:[NSMutableArray array] forKey:firstKey]; } // Add the object to the dictionary [[dict objectForKey:firstKey] addObject:[[NSMutableDictionary alloc] initWithObjects:item forKeys:[NSArray arrayWithObjects:@"name", @"url", nil]]]; // Add the object to the list for simple searching [fullList addObject:[[NSMutableDictionary alloc] initWithObjects:item forKeys:[NSArray arrayWithObjects:@"name", @"url", nil]]]; } filteredList = [NSMutableArray arrayWithCapacity:[fullList count]]; } #pragma mark - #pragma mark Table view data source // Custom method for object oriented data access - (NSString *)tableView:(UITableView *)tableView dataForRowAtIndexPath:(NSIndexPath *)indexPath withKey:(NSString *)key { return (NSString *)((tableView == self.searchDisplayController.searchResultsTableView) ? [[filteredList objectAtIndex:indexPath.row] objectForKey:key] : [[[dict objectForKey:[listIndex objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row] valueForKey:key]); } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return (tableView == self.searchDisplayController.searchResultsTableView) ? 1 : (([listIndex count] > 0) ? [[dict allKeys] count] : 1); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return (tableView == self.searchDisplayController.searchResultsTableView) ? [filteredList count] : [[dict objectForKey:[listIndex objectAtIndex:section]] count]; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return (tableView == self.searchDisplayController.searchResultsTableView) ? [[NSArray alloc] initWithObjects:nil] : listIndex; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return (tableView == self.searchDisplayController.searchResultsTableView) ? @"" : [listIndex objectAtIndex:section]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *kCellID = @"cellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } NSString * name = nil; // TODO: Make dataForRowAtIndexPath work here if (tableView == self.searchDisplayController.searchResultsTableView) { // NOTE: dataForRowAtIndexPath causes this to crash for some unknown reason. Maybe it is called before viewDidLoad and has no data? name = [[filteredList objectAtIndex:indexPath.row] objectForKey:@"name"]; } else { // This always works name = [self tableView:[self tableView] dataForRowAtIndexPath:indexPath withKey:@"name"]; } cell.textLabel.text = name; return cell; } #pragma mark Search Methods - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { // Clear the filtered array [self.filteredList removeAllObjects]; // Filter the array for (NSDictionary *item in fullList) { // Compare the item's name to the search text NSComparisonResult result = [[item objectForKey:@"name"] compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { // Add to the filtered array if it matches [self.filteredList addObject:item]; } } } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [self filterContentForSearchText:searchString scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; // Return YES to cause the search result table view to be reloaded. return YES; } - (void)viewDidUnload { filteredList = nil; } @end

    Read the article

  • UISearchDisplayController - how to display search result with only by scope button selected but empt

    - by billibala
    The UISearchDisplayController is very handy and implementing search is pretty straightforward. However, I bump into problem when, in my app, I want to display search result with empty search string but selected scope button. It seems like it's a must to enter some search string in order to get the search result table being initialized and displayed. Is there any ways to display search result immediately after user has picked a scope but not entered search word yet? Thanks Bill

    Read the article

  • Updating UISearchDisplayController with Core Data results using GCD

    - by Brian Halpin
    I'm having trouble displaying the results from Core Data in my UISearchDisplayController when I implement GCD. Without it, it works, but obviously blocks the UI. In my SearchTableViewController I have the following two methods: - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { // Tell the table data source to reload when text changes [self filterContentForSearchText:searchString]; // Return YES to cause the search result table view to be reloaded. return YES; } // Update the filtered array based on the search text -(void)filterContentForSearchText:(NSString*)searchText { // Remove all objects from the filtered search array [self.filteredLocationsArray removeAllObjects]; NSPredicate *predicate = [CoreDataMaster predicateForLocationUsingSearchText:@"Limerick"]; CoreDataMaster *coreDataMaster = [[CoreDataMaster alloc] init]; // Filter the array using NSPredicate self.filteredLocationsArray = [NSMutableArray arrayWithArray: [coreDataMaster fetchResultsFromCoreDataEntity:@"City" UsingPredicate:predicate]]; } You can probably guess that my problem is with returning the array from [coreDataMaster fetchResultsFromCoreDataEntity]. Below is the method: - (NSArray *)fetchResultsFromCoreDataEntity:(NSString *)entity UsingPredicate:(NSPredicate *)predicate { NSMutableArray *fetchedResults = [[NSMutableArray alloc] init]; dispatch_queue_t coreDataQueue = dispatch_queue_create("com.coredata.queue", DISPATCH_QUEUE_SERIAL); dispatch_async(coreDataQueue, ^{ NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entityDescription = [NSEntityDescription entityForName:entity inManagedObjectContext:self.managedObjectContext]; NSSortDescriptor *nameSort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObjects:nameSort, nil]; [fetchRequest setEntity:entityDescription]; [fetchRequest setSortDescriptors:sortDescriptors]; // Check if predicate is set if (predicate) { [fetchRequest setPredicate:predicate]; } NSError *error = nil; NSArray *fetchedManagedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error]; for (City *city in fetchedManagedObjects) { [fetchedResults addObject:city]; } NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:fetchedResults] forKey:@"results"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"fetchResultsComplete" object:nil userInfo:userInfo]; }); return [NSArray arrayWithArray:fetchedResults]; } So the thread hasn't finished executing by the time it returns the results to self.filteredLocationsArray. I've tried added a NSNotification which passes the NSDictionary to this method: - (void)updateSearchResults:(NSNotification *)notification { NSDictionary *userInfo = notification.userInfo; NSArray *array = [userInfo objectForKey:@"results"]; self.filteredLocationsArray = [NSMutableArray arrayWithArray:array]; [self.tableView reloadData]; } I've also tried refreshing the searchViewController like [self.searchDisplayController.searchResultsTableView reloadData]; but to no avail. I'd really appreciate it if someone could point me in the right direction and show me where I might be going wrong. Thanks

    Read the article

  • UISearchDisplayController changing row height

    - by tewha
    I've set my UITableView row height to in Interface Builder to 54.0. I have a UISearchDisplayController on that view. When the user taps the search bar in it, the table resizes properly. However, when they start typing (and actually doing the search) the row height decreases. It stays wrong until the search taps Cancel. I could find no documentation on this behavior on Apple's site. I've tried setting the row height in UISearchDisplayDelegate delegate calls. This might be the right approach, but I don't know the details and couldn't get it ti work. I've also tried implementing -- (CGFloat)tableView:(UITableView *)tableView -heightForRowAtIndexPath:(NSIndexPath *)indexPath;. This worked, but I have thousands of entries in this list and can't take the performance hit. What's the right way to fix this?

    Read the article

  • Why won't my UISearchDisplayController fire the shouldReloadTableForSearchString method when I enter

    - by Gorgando
    I've been following Apple's TableSearch code example, but it's not working for me and I think I'm doing everything the same way they did it. The method below should be fired whenever the user types anything into the search box, but it never gets fired for me, just on the sample app. I have the appropriate @interface ContactsTableVC : UITableViewController { in the header file. I'm not sure what I'm missing or where else to look. My NSLog never gets called. Thanks for the help! - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString searchScope:(NSInteger)searchOption { NSLog(@"The shouldreloadtableforsearchstring method has been called!"); [self filterContentForSearchText:searchString]; // Return YES to cause the search result table view to be reloaded. return YES; }

    Read the article

  • Multithreaded search with UISearchDisplayController

    - by Kulpreet
    I'm sort of new to any sort of multithreading and simply can't seem to get a simple search method working on a background thread properly. Everything seems to be in order with an NSAutoreleasePool and the UI being updated on the main thread. The app doesn't crash and does perform a search in the background but the search results yield the several of the same items several times depending on how fast I type it in. The search works properly without the multithreading (which is commented out), but is very slow because of the large amounts of data I am working with. Here's the code: - (void)filterContentForSearchText:(NSString*)searchText { NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init]; isSearching = YES; //[self.filteredListContent removeAllObjects]; // First clear the filtered array. for (Entry *entry in appDelegate.entries) { NSComparisonResult result = [entry.item compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.filteredListContent addObject:entry]; } } isSearching=NO; [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:(@selector(reloadData)) withObject:nil waitUntilDone:NO]; //[self.searchDisplayController.searchResultsTableView reloadData]; [apool drain]; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(filteredListContent:) object:searchString]; [self.filteredListContent removeAllObjects]; // First clear the filtered array. [self performSelectorInBackground:(@selector(filterContentForSearchText:)) withObject:searchString]; //[self filterContentForSearchText:searchString]; // Return YES to cause the search result table view to be reloaded. return NO; }

    Read the article

  • Increasing width of UISearchDisplayController PopOver Results

    - by George
    I have an iPad app that has a UISearchBar in its navigation bar. When I enter text in the search bar the results are automatically displayed in a UIPopOverController. That's great except the popover's default size is not wide enough for my needs. Is there a way to set its width? Apple has done this themselves with Safari's search bar. The popover that displays search results is a good bit wider than the default and they have removed the "Results" title from the popover.

    Read the article

  • UISearchDisplayController's full-screen background intercepts touch events in iOS 7

    - by tba
    I have a UITableview that doesn't take up the whole screen (screenshot). Everything worked fine in iOS 6. But in iOS 7, when the user searches, the search result table takes up the whole view (screenshot). To fix this, I tried setting the frame manually as described in this answer. The appearance is now correct (screenshot), but now the "<" button in the top left doesn't receive tap events when the search results table is displayed. It seems the searchResultsTableView is adding a full-screen background view that is intercepting touch events. To prove this, I added this code to didShowSearchResultsTableView: controller.searchResultsTableView.superview.backgroundColor = [UIColor blueColor];` This screenshot confirms my hypothesis. How can I fix this to allow the "<" button to receive tap events? I want to avoid modifying controller.searchResultsTableView.superview so that my change doesn't break in future versions of iOS. And what change in iOS 7 caused this behavior to start happening?

    Read the article

  • Is it possible to change the border color of a UISearchDisplayController's search bar?

    - by prendio2
    I have a UISearchBar added as my table header with the following code. searchBar = [[UISearchBar alloc] initWithFrame:self.tableView.bounds]; searchBar.tintColor = [UIColor colorWithWhite:185.0/255 alpha:1.0]; [searchBar sizeToFit]; self.tableView.tableHeaderView = searchBar; Then I set my UISearchDisplayController up as follows. searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; Everything functions as I would like except that the UISearchDisplayController has added a blue(ish) border above the search bar — this bar does not recognise the tintColor I have set on the search bar. Is it possible to change the color of this bar? It is obviously not absolutely crucial but that line is going to bug me forever if it stays blue like that!

    Read the article

  • UISearchDisplayController automatically creates a UIPopovercontroller to display content search result ?! How to dismiss it ?

    - by yonel
    Hi, I'm using a UISearchDisplayController with a UISearchBar. I put this UISearchBar in my app using IB and I get : Fine : when you start taping, the result popovercontroller appears magically (I didn't write anything on my own to make it appear !) Then, when a row is clicked among the result, I want to dismiss the PopoverController BUT at this stage, I never instantiated the UIPopoverController on my side : it looks like if there's an encapsulated behavior in the UISearchDisplayController that automatically wraps its searchContentsController inside a UIPopoverController. That's really great because everything works perfectly without doing anything except that I cannot get the reference to this UIPopoverController to dismiss it :( Does anyone know how to get the reference to this "magically" created UIPopoverController ? (this is the proof the iPad is really a "magical" device ;) I thought there would be a reference to the UIPopoverController from its contentController (through its parent property for instance), but I cannot find any way to get a pointer to it :/

    Read the article

  • UISearchDisplayController "shouldReloadTableForSearchString return NO" reloads table

    - by Jeena
    Why does my UISearchDisplayController show "No results" even if the shouldReloadTableForSearchString method returns NO? Shouldn't it just do nothing and stay black? How can I prevent it from doing so? #import "RootViewController.h" #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.searchDisplayController.searchResultsTableView) { return 0; } return 10; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. cell.textLabel.text = [NSString stringWithFormat:@"row %d", indexPath.row]; return cell; } #pragma mark SearchController stuff - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { return NO; } - (void)dealloc { [super dealloc]; } @end

    Read the article

  • Cannot get UISearchBar Scope Bar to appear in Toolbar (or anywhere) on iPad

    - by Jann
    This is really causing me fits. I see a lot of info on putting a UISearchBar in the top row of a UITableView -- but I am putting the UISearchBar into the Toolbar at the top of my screen (on the iPad). I cannot find ANYTHING regarding how to handle UISearchBar and UISearchDisplayController using a UIPopoverController on the iPad. Any more info about the UISearchDisplayController using a UIPopoverController would be greatly appreciated. Please help with this as I am at my wit's end. Using IB, I put a toolbar on the IUView on the iPad. I added the following: Search Bar (not Search Bar and Search Display) to the toolbar. I set the options to be as follows: Show Cancel Button, Show Scope Bar, Scope Button Titles are: "Title1" and "Title2" (with Title2's radio button selected). Opaque, Clear Context and Auto Resize are checked. I hooked up the delegate of Search Bar to the "File's Owner" and linked it to IBOutlet theSearchBar. In my viewWillAppear I have the following: //Just in case: [theSearchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]]; //Just in case (again): [theSearchBar setShowsScopeBar:YES]; //doesn't seem to do anything: //[theSearchBar sizeToFit]; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:theSearchBar contentsController:self]; [self setSearchDisplayController:searchDisplayController]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; //again--does not seem to do anything..but people have suggested it: [theSearchBar sizeToFit]; Okay, so far, I thought, so good. So, I made the File's Owner .m file to be a delegate for: UISearchBarDelegate, UISearchDisplayDelegate. My issue: I have yet to implement the delegates necessary to do the search but still... shouldn't I be seeing the scopeBar next to the search field when I click into the search field? Just so you know I DO see the log of the characters I type, so the delegate is working. I have the following dummy functions in the .m file (just in case) // called when keyboard search button pressed - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { NSLog(@"Search Button Clicked\n"); [theSearchBar resignFirstResponder]; } // called when cancel button pressed - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { NSLog(@"Cancel Button Clicked\n"); [theSearchBar resignFirstResponder]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { NSLog(@"Search Text So Far: '%@'\n",searchText); } - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { return YES; } - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { return YES; } Why doesn't the Scope Bar appear? A results UIPopoverController appears with the title "Results" and "No results found" (of course) when i type the first character in my search...but no scope bar. (not that i expect anything other than "No Results Found". I am wondering where the scope bar is supposed to appear...in the titleView of the UIPopover? In the toolbar to the right of the search area? Where?

    Read the article

  • Delegate Methods Not Firing on Search Results Table

    - by Slinky
    All, I have a UITableView w/detail, with a Search bar, created from code. Works fine on selected items except it doesn't work when an item is clicked from the search results; no delegate methods fire. Never seen this type of behavior before so I don't know where the issue lies. I get the same behavior with standard table cells as well as custom table cells. Appreciate any guidance on this and thanks. Just Hangs Here //ViewController.h @interface SongsViewController : UITableViewController <UISearchBarDelegate,UISearchDisplayDelegate> { NSMutableArray *searchData; UISearchBar *searchBar; UISearchDisplayController *searchDisplayController; UITableViewCell *customSongCell; } //ViewController.m -(void)viewDidLoad { [super viewDidLoad]; CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 88)]; [searchBar setShowsScopeBar:YES]; [searchBar setScopeButtonTitles:[[NSArray alloc] initWithObjects:@"Title",@"Style", nil]]; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; searchDisplayController.delegate = self; searchDisplayController.searchResultsDataSource = self; self.tableView.tableHeaderView = searchBar; //Load custom table cell UINib *songCellNib = [UINib nibWithNibName:@"SongItem" bundle:nil]; //Register this nib, which contains the cell [[self tableView] registerNib:songCellNib forCellReuseIdentifier:@"SongItemCell"]; // create a filtered list that will contain products for the search results table. SongStore *ps = [SongStore defaultStore]; NSArray *songObjects = [ps allSongs]; self.filteredListContent = [NSMutableArray arrayWithCapacity: [songObjects count]]; self.masterSongArr = [[NSMutableArray alloc] initWithArray:[ps allSongs]]; [self refreshData]; [self.tableView reloadData]; self.tableView.scrollEnabled = YES; }

    Read the article

  • Search Display Controller Crashes When Returning Results

    - by Convolution
    I have a tableview with a search display controller. It has been working fine in the past, but recently has started crashing for certain search results. Here my code searches a Golfer based on their Name, Age and Handicap. The data is correctly loaded into the table, I can access and drill down to receive further information. However when I type in a search query for either Name or Age, the app crashes, while the Golfers Handicap is returned fine. Note: dataSouceArray is the data source for the tableview, dataSourceArrayCopy is the mutable copy of the data used to add and remove objects in the search filter. - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { /* Update the filtered array based on the search text and scope. */ [self.dataSourceArrayCopy removeAllObjects]; // First clear the filtered array. /* Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array. */ for (Golfer *golfer in dataSourceArray) { if ([scope isEqualToString:@"Name"] || [golfer.golferName isEqualToString:scope]) { NSComparisonResult result = [golfer.golferName compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.customerListCopy addObject:golfer]; } } if ([scope isEqualToString:@"Age"] || [golfer.golferAge isEqualToString:scope]) { NSComparisonResult result = [golfer.golferAge compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.dataSourceArrayCopy addObject:golfer]; } } if ([scope isEqualToString:@"Handicap"] || [golfer.golferHandicap isEqualToString:scope]) { NSComparisonResult result = [golfer.golferHandicap compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.dataSourceArrayCopy addObject:golfer]; } } } } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [self filterContentForSearchText:searchString scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; // Return YES to cause the search result table view to be reloaded. return YES; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption { [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]]; // Return YES to cause the search result table view to be reloaded. return YES; } Any help would be appreciated, thank you for taking the time to read this.

    Read the article

  • Force scope bar below UISearchBar

    - by axiixc
    I have a UISearchBar and UISearchDisplayController, everything works great but my scope selector displays beside the text field instead of below it. I know that this is the expected action when the device is in landscape, but since I have the UISearchBar in the master view of a UISplitViewController it ends up looking like this http://cl.ly/BN9 Is there any way to force the scope bar to display below the text field in all interface orientations (I know that this works nicely in Mail.app on the iPad, so its possibly, but who knows if Apple decided to hide the option to do so)

    Read the article

  • searchdisplaycontroller: change the text of the searchbar

    - by kudorgyozo
    Hello, SHORT DESCRIPTION OF PROBLEM: I want to set the text of a searchbar without automatically triggering the search display controller that is bound to it. LONG DESCRIPTION OF PROBLEM: I have an iphone application with a search bar and a search display controller. The searchdisplaycontroller is used for autocomplete. For autocomplete i use an sqlite database. The user enters the first few letters of a keyword and the result are shown in the table of the searchdisplaycontroller. An sql select query is executed for every character typed. this part works ok, the letters have been entered and the results are visible. The problem is the following: If the user selects a row from the table I want to change the text of the searchbar to the text that was selected in the autocomplete results table. I also want to hide the search display controller. This is not working. After the search display controller disappears the textbox in the search bar is empty. I have no idea what's wrong. I didn't think something so simple as changing the text of a textbox can get so complicated. I have tried to change the text in 2 methods: First in the didSelectRowAtIndexPath method (for the search results table of the search display controller), but that didn't help. The text was there while the search display controller was active (animating away) but after that the textbox was empty. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"didSelectRowAtIndexPath"); if (allKeywords.count 0) { didSelectKeyword = TRUE; self.selectedKeyword = (NSString *)[allKeywords objectAtIndex: indexPath.row]; NSLog(@"keyword didselectrow at idxp: %@", self.selectedKeyword); shouldReloadResults = FALSE; [[self.mainViewController keywordSearchBar] setText: selectedKeyword]; //shouldReloadResults = TRUE; [[mainViewController searchDisplayController] setActive:NO animated: YES]; } } I also tried to change it in the searchDisplayControllerDidEndSearch method but that didn't help either. The textbox was...again.. empty. edit: actually it wasnt empty the text was there but after the disappearing animation the results of the autocomplete table are still there. So it ends up getting worse. - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { NSLog(@"searchDisplayControllerDidEndSearch"); if (didSelectKeyword) { shouldReloadResults = FALSE; NSLog(@"keyword sdc didendsearch: %@", selectedKeyword); [[mainViewController keywordSearchBar] setText: selectedKeyword]; // In this method i call another method which selects the data from sqlite. This part is working. - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { NSLog(@"shouldReloadResults : %i", shouldReloadResults); if (shouldReloadResults) { NSLog(@"shouldReloadTableForSearchString: %@", searchString); [self GetKeywords: searchString : @"GB"]; NSLog(@"shouldReloadTableForSearchString vege"); return YES; } return NO; } Please ask me if it's not clear what my problem is. I need your help. Thank you

    Read the article

  • UISearchBar animation hidding button

    - by David Carvalho
    Hello I currently have a UISearchBar (attached to a UISearchDisplayController), but I reduced the width of the search bar so I could display a custom button to its right when the search bar is not selected. The button is used to access other views. However, when I select the search bar and then press cancel (or even perform a search) and return to the normal view, where the search bar should be displayed with my custom button, the search bar animates and takes up all the room for the button and the is not displayed. Essentially, the search bar takes up all the width of the screen when I only want it to take up a part of it. Is there any way to prevent the search bar from animating to the whole width of the screen? This is how I defined the CGRect of the search bar: self = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 250.0f, 45.0f)] Any help would be great. Regards

    Read the article

  • iPhone Text entry with completion and DONE button (not search)

    - by Adam Jack
    Using iPhone SDK 3.0, I wish to allow text entry with (optional) completion options that appear as typing is occurring, i.e. also allowing freeformat entry. As such I am using a UISearchBar (which has the text change events) and a UISearchDisplayController to present options. The problems is I want the DONE button to say DONE and not SEARCH, however I cannot find a way to set that. Clearly I feel I am missing something, or Interface Builder of the SDK API would have some property to set. I have seen other apps (in the store) that have achieved the result I want (free format entry, completion, DONE button) so maybe there is an alternative approach I am missing. Thanks in advance for any pointers.

    Read the article

  • UISearchBar in a UITableView

    - by petert
    I'm trying to mimic the behaviour of a table view like one in the iPod app for Artists - it's a sectioned table view with a section index on the right and with a search bar at the top, but initially hidden when view shown. I am using sdk 3.1.2 and IB, so simply dragged a UISearchDisplayController in to my NIB - it does wire everything up ready for searching. The problem starts because I'm adding the UISearchBar in to the first section of the UITableView, because if I understand correctly I must do this so I can jump to the search bar by touching the search icon in the section index directly? When the table view appears I see the search bar but it has resized and I now have a white block behind the section index at the top. It does'nt take the color of the UISearchBar's surround which interestingly is different to that shown in Interface Builder. Searching around, I did find a tip to add a small navigation bar and a UISearchBar in a UIView, then add this to the table view cell - this works.. BUT the color of the navigation bar's background is what you'd expect normally (gray), not the different color as noted above?! More interesting, if I click the search bar to start a search, then click Cancel, all is fixed!!! The background along the whole tableview cell when the search bar is, is the same!!?! Thanks for any tips.

    Read the article

  • UITableView and SearchBar problem

    - by dododedodonl
    Hi all, I'm trying to add a Search bar to my UITableView. I followed this tutorial: http://clingingtoideas.blogspot.com/2010/02/uitableview-how-to-part-2-search.html. I'm getting this error if I type a letter in the search box: Rooster(10787,0xa05ed4e0) malloc: *** error for object 0x3b5f160: double free *** set a breakpoint in malloc_error_break to debug. This error occurs here: - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [self handleSearchForTerm:searchString]; return YES; } (on the second line) - (void)handleSearchForTerm:(NSString *)searchTerm { [self setSavedSearchTerm:searchTerm]; if ([self searchResults] == nil) { NSMutableArray *array = [[NSMutableArray alloc] init]; [self setSearchResults:array]; [array release]; } //Empty the searchResults array [[self searchResults] removeAllObjects]; //Check if the searchTerm doesn't equal zero... if ([[self savedSearchTerm] length] != 0) { //Search the whole tableList (datasource) for (NSString *currentString in tableList) { NSString *klasString = [[NSString alloc] init]; NSInteger i = [[leerlingNaarKlasList objectAtIndex:[tableList indexOfObject:currentString]] integerValue]; if(i != -1) { klasString = [klassenList objectAtIndex:(i - 1)]; } //Check if the string matched or the klas (group of school) if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound || [klasString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound) { //Add to results [[self searchResults] addObject:currentString]; //Save the klas (group of school). It has the same index as the result (lastname) NSString *strI = [[NSString alloc] initWithFormat:@"%i", i]; [[self searchResultsLeerlingNaarKlas] addObject:strI]; [strI release]; } [klasString release]; } } } Can someone help me out? Regards, Dodo

    Read the article

  • iPhone Multithreaded Search

    - by Kulpreet
    I'm sort of new to any sort of multithreading and simply can't seem to get a simple search method working on a background thread properly. Everything seems to be in order with an NSAutoreleasePool and the UI being updated on the main thread. The app doesn't crash and does perform a search in the background but the search results yield the several of the same items several times depending on how fast I type it in. The search works properly without the multithreading (which is commented out), but is very slow because of the large amounts of data I am working with. Here's the code: - (void)filterContentForSearchText:(NSString*)searchText { isSearching = YES; NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init]; /* Update the filtered array based on the search text and scope. */ //[self.filteredListContent removeAllObjects]; // First clear the filtered array. for (Entry *entry in appDelegate.entries) { NSComparisonResult result = [entry.gurmukhiEntry compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.filteredListContent addObject:entry]; } } [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:(@selector(reloadData)) withObject:nil waitUntilDone:NO]; //[self.searchDisplayController.searchResultsTableView reloadData]; [apool drain]; isSearching = NO; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { if (!isSearching) { [self.filteredListContent removeAllObjects]; // First clear the filtered array. [self performSelectorInBackground:(@selector(filterContentForSearchText:)) withObject:searchString]; } //[self filterContentForSearchText:searchString]; return NO; // Return YES to cause the search result table view to be reloaded. }

    Read the article

  • Cannot get UISearchBar Scope Bar to appear in Toolbar on iPad

    - by Jann
    This is really causing me fits. I put a toolbar on the IUView on the iPad. I added the following: Search Bar (not Search Bar and Search Display) to the toolbar. I set the options to be as follows: Show Cancel Button, Show Scope Bar, Scope Button Titles are: "Title1" and "Title2" (with Title2's radio button selected). Opaque, Clear Context and Auto Resize are checked. I hooked up the delegate of Search Bar to the "File's Owner" and linked it to IBOutlet theSearchBar. In my viewWillAppear I have the following: [theSearchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]]; //Just in case: [theSearchBar setShowsScopeBar:YES]; //doesn't seem to do anything: //[theSearchBar sizeToFit]; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:theSearchBar contentsController:self]; [self setSearchDisplayController:searchDisplayController]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; //again--does not seem to do anything..but people have suggested it: [theSearchBar sizeToFit]; Okay, so far, I thought, so good. So, I made the File's Owner .m file to be a delegate for: UISearchBarDelegate, UISearchDisplayDelegate. My issue: I have yet to implement the delegates necessary to do the search but still... shouldn't I be seeing the scopeBar next to the search field when I click into the search field? Just so you know I DO see the log of the characters I type, so the delegate is working. I have the following dummy functions in the .m file (just in case) // called when keyboard search button pressed - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { NSLog(@"Search Button Clicked\n"); [theSearchBar resignFirstResponder]; } // called when cancel button pressed - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { NSLog(@"Cancel Button Clicked\n"); [theSearchBar resignFirstResponder]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { NSLog(@"Search Text So Far: '%@'\n",searchText); } - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { return YES; } - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { return YES; } Why doesn't the Scope Bar appear? A results UIPopoverController appears with the title "Results" and "No results found" (of course) when i type the first character in my search...but no scope bar. (not that i expect anything other than "No Results Found". I am wondering where the scope bar is supposed to appear...in the titleView of the UIPopover? In the toolbar to the right of the search area? Where?

    Read the article

  • NSPredicates, scopes and SearchDisplayController

    - by Bryan Veloso
    Building a search with some custom objects and three scopes: All, Active, and Former. Got it working with the below code: - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString *)scope { [[self filteredArtists] removeAllObjects]; for (HPArtist *artist in [self artistList]) { if ([scope isEqualToString:@"All"] || [[artist status] isEqualToString:scope]) { NSComparisonResult result = [[artist displayName] compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [[self filteredArtists] addObject:artist]; } } } } This works fine and takes scope into account. Since I wanted to search four fields at at time, this question helped me come up with the below code: - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString *)scope { [[self filteredArtists] removeAllObjects]; NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"familyName CONTAINS[cd] %@ OR familyKanji CONTAINS[cd] %@ OR givenName CONTAINS[cd] %@ OR givenKanji CONTAINS[cd] %@", searchText, searchText, searchText, searchText]; [[self filteredArtists] addObjectsFromArray:[[self artistList] filteredArrayUsingPredicate:resultPredicate]]; } However it no longer takes scope into account. I have been playing around with if statements, adding AND scope == 'Active', etc. to the end of the statement and using NSCompoundPredicates to no avail. Whenever I activate a scope, I'm not getting any matches for it. Just a note that I've seen approaches like this one that take scope into account, however they only search inside one property.

    Read the article

1 2  | Next Page >