Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "-[NSCFString sizeWithTextStyle:]: unrecognized selector" in IPhone SDK

I get the following error while running my app.

'-[NSCFString sizeWithTextStyle:]: unrecognized selector

I have not used sizeWithTextStyle in my entire project.

So what could be wrong?

I get error on return pos; statement below

Code:

(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

like image 528
Parth Bhatt Avatar asked Feb 18 '11 10:02

Parth Bhatt


3 Answers

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.
like image 34
dreamlax Avatar answered Nov 14 '22 23:11

dreamlax


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 **
like image 147
iHS Avatar answered Nov 14 '22 21:11

iHS


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"

like image 3
Preethi Avatar answered Nov 14 '22 22:11

Preethi