Note that there are some explanatory texts on larger screens.

plurals
  1. POUITabelView with UISearchDisplayDelegate
    text
    copied!<p>I'm trying to set up a simple UITableView with a UISearchDisplayDelegate but my app keeps crashing with a SIGABRT error for : [self.filteredListContent removeAllObjects]; </p> <p>Any ideas on why this is happening</p> <pre><code>#import "SearchViewController.h" @implementation SearchViewController @synthesize listContent, filteredListContent; - (void)viewDidLoad { [super viewDidLoad]; listContent = [[NSArray alloc]initWithObjects:@"hello", @"bye", nil]; filteredListContent = [NSMutableArray arrayWithCapacity:listContent.count]; [self.tableView reloadData]; self.tableView.scrollEnabled = YES; } - (void)viewDidUnload { [super viewDidUnload]; self.listContent =nil; self.filteredListContent=nil; } -(void) dealloc { [super dealloc]; [self.listContent release]; [self.filteredListContent release]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. if (tableView == self.searchDisplayController.searchResultsTableView) { return [self.filteredListContent count]; } else { return [self.listContent count]; } } - (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]; } NSString *label; if (tableView == self.searchDisplayController.searchResultsTableView) { label = [self.filteredListContent objectAtIndex:indexPath.row]; } else { label = [self.listContent objectAtIndex:indexPath.row]; } cell.textLabel.text = label; return cell; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (void)filterContentForSearchText:(NSString*)searchText { [self.filteredListContent removeAllObjects]; for (NSString *string in listContent) { NSComparisonResult result = [string compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.filteredListContent addObject:string]; } } } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [self filterContentForSearchText:searchString]; return YES; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption { [self filterContentForSearchText:[self.searchDisplayController.searchBar text]]; return YES; } </code></pre> <p>header file</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface SearchViewController : UITableViewController&lt;UISearchDisplayDelegate, UISearchBarDelegate&gt; { NSArray *listContent; NSMutableArray *filteredListContent; } @property (nonatomic, retain) NSArray *listContent; @property (nonatomic, retain) NSMutableArray *filteredListContent; @end </code></pre>
 

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