Error: “-: unrecognized selector” in IPhone SDK

I get the following error while running my app.

‘-[NSCFString sizeWithTextStyle:]: unrecognized selector

  • How to check text field input at real time?
  • Implementing iOS Maps style page curl gesture interactions
  • UITableView : detecting click on '-' button in edit mode
  • Losing a / when converting from NSURL to NSURLRequest
  • UICollectionView Flow layout no fixed row height
  • How to get phone number from address book as string?
  • I have not used sizeWithTextStyle in my entire project.

    So what could be wrong?

    I get error on return pos; statement below


    (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
         UIView *pos = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,35.0)];
         return pos;

    Error in Console:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString sizeWithTextStyle:]: unrecognized selector sent to instance 0x7044b50'

    Because of indentation problem while putting whole crash log here, I am putting the screenshot of the crash log

    enter image description here

    4 Solutions Collect From Internet About “Error: “-: unrecognized selector” in IPhone SDK”

    I think, the problem is somewhere else, not in this line of code. The object is not able to retain itself. Post the code, where you are using the sizeWithTextStyle method

    Have you the -all_load flag on your link settings?

    This issue comes up a lot. You need to add -all_load and -ObjC to your applications link flags.

    *EDIT : *

    Crash appears to occur on line:

     CGSize textSize = [self.text sizeWithTextStyle:textStyle];
     in class: CPTextLayer method: sizeToFit
     which is called from within class CPTextLayer method initWithText:
    -(id)initWithText:(NSString *)newText style:(CPTextStyle *)newStyle
    [self sizeToFit];
    **try to set with iOS 4 and not with 3.1.3 **

    When you have memory management issues (selectors being sent to the wrong instances is one symptom of memory management issues), there are a number of things you can do:

    1. Re-read the Cocoa memory management rules and make sure that you’re following them.
    2. Run the static analyser. This will often pick up places where you have neglected the memory management rules.
    3. Try using NSZombieEnabled to find out whether [and when] you are sending messages to unallocated instances.

    I am also getting same error but now it’s solved.

    Need to do simple thing, set the value of Other linker flag.

    below I have mention the steps.

    Project name – Build Setting – Other linker flag (use search bar to search) – “-ObjC”

    You should change your code to use pointers like this:

    UIView *pos = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,35.0)]; 
         return pos;

    Pay attention to asterisk!

    And of course the ; in the end of allocation statement!