NSMutableArray getting : unrecognized selector sent to instance

I really need some help...

When I try to get the number of cells for section using a NSMutableArray, I get [__NSCFString count]: unrecognized selector sent to instance 0x6d567e0

This happens when I use "rows = [[searchProfile objectAtIndex:section] count];"

Here is the code:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"1");
    // _________ Return the number of sections ________
    int sections =  0;

    if (tableView == self.tableView)
    {
        sections = 2;
    }
    if (tableView == self.searchDisplayController.searchResultsTableView)
    {
        sections = [searchedProfile count];
    }
    return sections;
}


/* ------------------------------------------ Set The Number Of Cells for Each Section ------------------------------- */


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"2");

    // _________  Return the number of rows in the section. ________
    int rows = 0;

    if (tableView == self.tableView)
    {
        if (section == 0) {
            rows = userProfile.count;}
        else {
            rows = profiles.count;}
    }

    if (tableView == self.searchDisplayController.searchResultsTableView)
    {
        rows = [[searchedProfile objectAtIndex:section]count];
    }
    return rows;
}

And the method that inserts strings into "searchedProfile" array:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    searchedKeys = [NSMutableArray array];
    searchedProfile = [NSMutableArray array];
    searchedData = [NSMutableDictionary dictionary];

    [searchedProfile removeAllObjects];
    [searchedData removeAllObjects];
    [searchedKeys removeAllObjects];


        NSDictionary *profile;

        for (profile in profiles)
        {
            NSString *birthname;
            NSString *currentname;
            NSString *photopath;
            NSDate *birthdate;

            for (birthname in profile)
            {
                birthname = [profile objectForKey:@"birthname"];
                currentname = [profile objectForKey:@"currentname"];
                photopath = [profile objectForKey:@"profilepic"];
                birthdate = [profile objectForKey:@"birthdate"];
                NSRange nameRange = [birthname rangeOfString:searchString options:NSCaseInsensitiveSearch];

                if (nameRange.location != NSNotFound)
                {
                    [searchedProfile addObject:birthname];
                    [searchedData setObject:birthname forKey:@"birthname"];
                    [searchedData setObject:currentname forKey:@"currentname"];
                    [searchedData setObject:photopath forKey:@"profilepic"];
                    [searchedData setObject:birthdate forKey:@"birthdate"];
                    if ([birthname isEqualToString:[profile objectForKey:@"birthname"]])
                        break;
                }
            }
        }
    NSLog(@"SEARCHED PROFILES: %@", searchedProfile);
    NSLog(@"SEARCHED DATA:%@", searchedData);
    NSLog(@"SEARCHED KEYS:%@", searchedKeys);
    NSLog(@"count test: %d", searchedProfile.count);
    return YES;
}

Thank you !

Answers


It looks like you're using the count method for NSArray's on an NSString, which is not allowed. You store NSStrings in the array searchedProfile, and it looks like you want to find out the length of a string. So instead of this:

    rows = [[searchedProfile objectAtIndex:section] count];

Do this:

    rows = [[searchedProfile objectAtIndex:section] length];

Need Your Help

move_uploaded_file not working in ubuntu 10.04

php

hey guys, am having a bit of a problem here, move_uploaded_file is not actually working at all, and its showing some warnings in my terminal.

Any experience with replacing BOOST_FOREACH by range-based for loop from C++11?

c++ visual-c++ boost c++11

Did you ever went through the process of replacing the BOOST_FOREACH by the range-based for loop? Are there any gotchas when doing it mechanically (i.e. not doing a deep study of the code around).