Parth Bhatt
Parth Bhatt

Reputation: 19469

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

Upvotes: 16

Views: 4607

Answers (4)

Preethi
Preethi

Reputation: 195

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"

Upvotes: 3

iHS
iHS

Reputation: 5432

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 **

Upvotes: 29

dreamlax
dreamlax

Reputation: 95325

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.

Upvotes: 4

Nava Carmon
Nava Carmon

Reputation: 4533

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!

Upvotes: 0

Related Questions