Question

I have a problem with a searchBar, i get an error unrecognized selector.

2013-02-11 14:48:27.211 Scores (FREE)[13946:c07] test ijsid CONTAINS[cd] "A" 2013-02-11 14:48:27.213 Scores (FREE)[13946:c07] test ( Axel, "Double Axel", "Triple Axel", "Quad Axel" ) 2013-02-11 14:48:27.213 Scores (FREE)[13946:c07] -[SingleElements isEqualToString:]: unrecognized selector sent to instance 0x755a5f0 2013-02-11 14:48:27.214 Scores (FREE)[13946:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SingleElements isEqualToString:]: unrecognized selector sent to instance 0x755a5f0' * First throw call stack: (0x209f012 0x11ace7e 0x212a4bd 0x208ebbc 0x208e94e 0x249e9f 0x24a064 0x2ae4 0x1ab8fb 0x1ab9cf 0x1941bb 0x192872 0x19d701 0x1a5d5d 0x1ade04 0x3d55f5 0x3d809e 0x327cc5 0x11c0705 0xf4213 0x1b5c7e 0x1b5310 0x1c213c 0x1cc5a6 0xc6d4f9 0x20f90c5 0x2053efa 0xba1bb2 0x38a39de 0x29f11da 0x2e2adfc 0x2e2dbf8 0x387e612 0x387e74a 0x387eec0 0x387ecb8 0x387e204 0x2c6c22b 0x2c6c193 0x3850e96 0x387d4cc 0x2e28136 0x2e273c6 0x2e5a980 0x34b67fd 0x2e51576 0x2e526da 0x2e5072e 0x34b4eaa 0x2e6aaf1 0x2e5a72a 0x2e2e6ae 0x2a2d62b 0x11c06b0 0x3899810 0x2a6c1a4 0x2a6e2ff 0x2b20b4 0x274aef 0x275e58 0x2749fe 0x27ed29 0x101ddb 0x1ff7f5 0x1ff7f5 0x1ff7f5 0x1ff7f5 0x1ff7f5 0x1ff7f5 0x1ff7f5 0x1ff7f5 0x1ff7f5 0x101e35 0x101806 0x101beb 0xf3698 0x1ffadf9 0x1ffaad0 0x2014bf5 0x2014962 0x2045bb6 0x2044f44 0x2044e1b 0x1ff97e3 0x1ff9668 0xf0ffc 0x1f8d 0x1eb5) libc++abi.dylib: terminate called throwing an exception

(lldb) po 0x755a5f0 $0 = 123053552 Axel

.h

@interface SingleElementsVC : UITableViewController{
    NSMutableArray *thesingleelementslist;
    sqlite3 * db;
    UISearchDisplayController *searchDisplayController;
    UISearchDisplayController *searchBar;
    NSMutableArray *searchResults;

}

@property(nonatomic,retain) NSMutableArray *thesingleelementslist;
@property(nonatomic, strong)SingleElementsDetailView *details;

-(NSMutableArray *) singleElementsList;
@property (nonatomic, retain) IBOutlet UISearchDisplayController *searchDisplayController;
@property (nonatomic, retain) IBOutlet UISearchDisplayController *searchBar;
@property (nonatomic, copy) NSMutableArray *searchResults;

@end

.m

@interface SingleElementsVC ()

@end

@implementation SingleElementsVC
@synthesize thesingleelementslist;
@synthesize searchDisplayController;
@synthesize searchBar;
@synthesize searchResults;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self singleElementsList];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (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;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *sectionHeader = nil;
    sectionHeader = @"Scale Of Values For Single";
    return sectionHeader;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    NSInteger rows = 0;

    if ([tableView
         isEqual:self.searchDisplayController.searchResultsTableView]){
        rows = [self.searchResults count];
    }
    else{
        rows = [self.thesingleelementslist count];
    }

    return rows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SingleElementsCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
        cell.textLabel.text = [self.searchResults objectAtIndex:indexPath.row];
    }
    else{
        SingleElements *singleElements = [self.thesingleelementslist objectAtIndex:indexPath.row];
        cell.textLabel.text = singleElements.ijsid;
        NSString *singleElementsDescriptionAndBase = [NSString stringWithFormat:@"%@ (%@)",singleElements.description, singleElements.base];
        cell.detailTextLabel.text = singleElementsDescriptionAndBase;
    }

    return cell;
}

-(NSMutableArray *) singleElementsList{
    thesingleelementslist = [[NSMutableArray alloc] initWithCapacity:10];
    @try {
        NSFileManager *fileMgr = [NSFileManager defaultManager];
        NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"ElementsDb.sqlite"];
        BOOL success = [fileMgr fileExistsAtPath:dbPath];
        if(!success)
        {
            NSLog(@"Cannot locate database file '%@'.", dbPath);
        }
        if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
        {
            NSLog(@"An error has occured: %s", sqlite3_errmsg(db));

        }
        const char *sql = "SELECT * FROM single";
        sqlite3_stmt *sqlStatement;
        if(sqlite3_prepare(db, sql, -1, &sqlStatement, NULL) != SQLITE_OK)
        {
            NSLog(@"Problem with prepare statement:  %s", sqlite3_errmsg(db));
        }else{

            while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
                SingleElements * singleElements = [[SingleElements alloc] init];
                singleElements.group = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
                singleElements.ijsid = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,2)];
                singleElements.description = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,3)];
                singleElements.plus3 = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,4)];
                singleElements.plus2 = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,5)];
                singleElements.plus1 = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,6)];
                singleElements.base = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,7)];
                singleElements.baseur = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,8)];
                singleElements.minus1 = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,9)];
                singleElements.minus2 = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,10)];
                singleElements.minus3 = [[NSDecimalNumber alloc] initWithDouble:sqlite3_column_double(sqlStatement,11)];
                singleElements.goeplus3 = [singleElements.plus3 decimalNumberByAdding:singleElements.base];
                singleElements.goeplus2 = [singleElements.plus2 decimalNumberByAdding:singleElements.base];
                singleElements.goeplus1 = [singleElements.plus1 decimalNumberByAdding:singleElements.base];
                singleElements.goeminus1 = [singleElements.minus1 decimalNumberByAdding:singleElements.base];
                singleElements.goeminus2 = [singleElements.minus2 decimalNumberByAdding:singleElements.base];
                singleElements.goeminus3 = [singleElements.minus3 decimalNumberByAdding:singleElements.base];
                [thesingleelementslist addObject:singleElements];
            }
        }
    }
    @catch (NSException *exception) {
        NSLog(@"Problem with prepare statement:  %s", sqlite3_errmsg(db));
    }
    @finally {
        sqlite3_close(db);

        return thesingleelementslist;
    }
}

- (void)filterContentForSearchText:(NSString*)searchText
                             scope:(NSString*)scope
{
    NSPredicate *resultPredicate = [NSPredicate
                                    predicateWithFormat:@"ijsid contains[cd] %@",
                                    searchText];

    self.searchResults = [NSMutableArray arrayWithArray:[self.thesingleelementslist filteredArrayUsingPredicate:resultPredicate]];

     NSLog(@"test %@", searchResults);
}

#pragma mark - UISearchDisplayController delegate methods
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

    return YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
    [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];

    return YES;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    //if ([[segue identifier] isEqualToString:@"showDetail"]) {

        SingleElementsDetailView *detailViewController = [segue destinationViewController];
        SingleElements *singleElements = [[SingleElements alloc]init];
        detailViewController.singleElements = [self.singleElementsList objectAtIndex:[self.tableView indexPathForSelectedRow].row];
        singleElements = [self.singleElementsList objectAtIndex:[self.tableView indexPathForSelectedRow].row];

        NSLog(@"test %@", singleElements.ijsid);
        NSLog(@"test %@", singleElements.description);
        NSLog(@"test %@", singleElements.goeplus3);
        NSLog(@"test %@", singleElements.goeplus2);
        NSLog(@"test %@", singleElements.goeplus1);
        NSLog(@"test %@", singleElements.base);
        NSLog(@"test %@", singleElements.goeminus1);
        NSLog(@"test %@", singleElements.goeminus2);
        NSLog(@"test %@", singleElements.goeminus3);
    //}
}

@end

Class SingleElements.h

@interface SingleElements : NSObject{
    NSString *group;
    NSString *ijsid;
    NSString *description;
    NSDecimalNumber *plus3;
    NSDecimalNumber *plus2;
    NSDecimalNumber *plus1;
    NSDecimalNumber *base;
    NSDecimalNumber *baseur;
    NSDecimalNumber *minus1;
    NSDecimalNumber *minus2;
    NSDecimalNumber *minus3;
    NSDecimalNumber *goeplus3;
    NSDecimalNumber *goeplus2;
    NSDecimalNumber *goeplus1;
    NSDecimalNumber *goeminus1;
    NSDecimalNumber *goeminus2;
    NSDecimalNumber *goeminus3;
}

@property(nonatomic,copy) NSString *group;
@property(nonatomic,copy) NSString *ijsid;
@property(nonatomic,copy) NSString *description;
@property(nonatomic,copy) NSDecimalNumber *plus3;
@property(nonatomic,copy) NSDecimalNumber *plus2;
@property(nonatomic,copy) NSDecimalNumber *plus1;
@property(nonatomic,copy) NSDecimalNumber *base;
@property(nonatomic,copy) NSDecimalNumber *baseur;
@property(nonatomic,copy) NSDecimalNumber *minus1;
@property(nonatomic,copy) NSDecimalNumber *minus2;
@property(nonatomic,copy) NSDecimalNumber *minus3;
@property(nonatomic,copy) NSDecimalNumber *goeplus3;
@property(nonatomic,copy) NSDecimalNumber *goeplus2;
@property(nonatomic,copy) NSDecimalNumber *goeplus1;
@property(nonatomic,copy) NSDecimalNumber *goeminus1;
@property(nonatomic,copy) NSDecimalNumber *goeminus2;
@property(nonatomic,copy) NSDecimalNumber *goeminus3;

@end

Any help are welcome, thanks.

Was it helpful?

Solution

Is SingleElements subclass of NSString ??

My guess would be isEqualToString is not available for SingleElements.

Can you post code for SingleElements class?

EDIT: From your updated question I can see that it's a subclass of NSObject which hasn't any idea with what isEqualToString has to do with.

For getting to the line of crash (which you will not have any clue, If I guessed it right), Try to do as following:

  1. Go to the breakpoints navigator in the left pane.
  2. Click the plus button at the bottom of the screen.
  3. Choose Add Exception Breakpoint
  4. In the bubble that pops up choose Objective-C in the Exception field.
  5. Execute the program again

Now, Try to have that exception again. XCode will bring you to that line before crashing. Then, Post that line here. May be then, We can go for the solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top