NSCFString unrecognized selector

Discussion in 'iOS Development' started by Chicken, May 2, 2009.

  1. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    When trying to delete rows from a table view I get an error in GDB saying

    Code:
    [NSCFString count]: unrecognized selector sent to instance 0x575e00
    I can post my code if you need it.

    Thanks

    - Chicken
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    That's because there is no "count" method for NSString. If you're trying to get the length of the string, use "length."
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Post your code, as I think you may be trying to get at an NSArray, but are doing so incorrectly. You are instead accessing a string.
  4. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    OK bearing in mind this is the first time I have worked with table views this is where I think I am going wrong

    Code:
    // Override to support editing the table view.
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            // Delete the row from the data source
    		[tableView deleteRowsAtIndexPaths:[itemsArray objectAtIndex:indexPath.row] withRowAnimation:YES];
        }   
        else if (editingStyle == UITableViewCellEditingStyleInsert) {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }   
    }
    
    Again this is the first time I have used table views.
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    deleteRowsAtIndexPaths: wants an array of index paths to delete.
  6. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    OK thanks, I'll look into it.
  7. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55

    I think I see a couple errors here.

    1. Argument 2 of -deleteRowsAtIndexPaths:withRowAnimation: takes a parameter which is UITableViewRowAnimation, not a boolean. Pass something like UITableViewRowAnimationRight or UITableViewRowAnimationFade.

    2. You're trying to pull something out of your array based on the row of the NSIndexPath sent in that method. What you want to do is pass an NSArray that has one object, the NSIndexPath passed, and then it should work properly.

    Example:
    Code:
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
            if (editingStyle == UITableViewCellEditingStyleDelete) {
                    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
            }     
    }
    Try that.

Share This Page