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

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

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:
Re-read the Cocoa memory management rules and make sure that you're following them.
Run the static analyser. This will often pick up places where you have neglected the memory management rules.
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!

Related

Why am I getting an "unrecognised selector sent to instance" error when I have defined the method?

I'm building an iOS (5.1) app on Xcode (4.4.1), and I'm almost done with the first phase of development, but I'm stuck on the final line of code. I've been using Kumulos as a backend & API solution, and at the moment all the API is working fine except for this bit:
Kumulos* k = [[Kumulos alloc]init];
[k setDelegate:self];
[k createNewTimePointWithJourneyIDFK:[journeyID integerValue]
andTime:currentDate andLat:[lat floatValue] andLon:[lon floatValue]];
When it hits the createNewTimePointWithJourneyIDFK: method, it terminates. In the log it mentions this method and says an unrecognised selector was sent to an instance.
Now I realise this question has been asked a million times on SO, but I've 1) checked that the method has been defined, and 2) that it has been called correctly (or at least to the best of my knowledge). The way I've done the above is the way I've done the rest of the API calls, and they work well, so I can't see what the problem is. Very frustrating, I've spent hours on this last line! So please don't think I've come hear after a few minutes of not knowing what to do.
The error message
2012-08-11 22:36:58.769 busApp4Kumulos[5485:707] -[Kumulos
createNewTimePointWithJourneyIDFK:andTime:andLat:andLon:]:
unrecognizedselector sent to instance 0x3d1b70 2012-08-11 22:36:58.778
busApp4Kumulos[5485:707]
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[Kumulos
createNewTimePointWithJourneyIDFK:andTime:andLat:andLon:]:
unrecognized selector sent to instance 0x3d1b70'
*** First throw call stack:
(0x35add88f 0x37e84259 0x35ae0a9b 0x35adf915 0x35a3a650 0x3ef5
0x37f86de3 0x37f86785 0x37f80e3f 0x35ab1b01 0x35ab112f 0x35ab0351
0x35a334a5 0x35a3336d 0x376cf439 0x3353fcd5 0x2dd9 0x2d74)
terminate called throwing an exception(lldb)
The Method
This is located in the Kumulos.m file.
-(KSAPIOperation*) createNewTimePointWithJourneyIDFK:(NSInteger)journeyIDFK
andTime:(NSDate*)time andLat:(float)lat andLon:(float)lon{
NSMutableDictionary* theParams = [[NSMutableDictionary alloc]init];
[theParams setValue:[NSNumber numberWithInt:journeyIDFK] forKey:#"journeyIDFK"];
[theParams setValue:time forKey:#"time"];
[theParams setValue:[NSNumber numberWithFloat:lat] forKey:#"lat"];
[theParams setValue:[NSNumber numberWithFloat:lon] forKey:#"lon"];
KSAPIOperation* newOp = [[KSAPIOperation alloc]initWithAPIKey:theAPIKey
andSecretKey:theSecretKey andMethodName:#"createNewTimePoint"
andParams:theParams];
[newOp setDelegate:self];
[newOp setUseSSL:useSSL];
//we pass the method signature for the kumulosProxy callback on this thread
[newOp setCallbackSelector:#selector( kumulosAPI: apiOperation: createNewTimePointDidCompleteWithResult:)];
[newOp setSuccessCallbackMethodSignature:[self methodSignatureForSelector:#selector(apiOperation: didCompleteWithResult:)]];
[newOp setErrorCallbackMethodSignature:[self methodSignatureForSelector:#selector(apiOperation: didFailWithError:)]];
[opQueue addOperation:newOp];
return newOp;
}
The only thing I can think of is that something got stale in your project. Have you tried cleaning (via Product → Clean) and rebuilding?

unrecognized selector sent to instance - mistake in properties?

I know that this question is asked for many times but i am working on it hard and can not find the mistake!
I have made a navigation based application.
To costumize the appereance of the table view cells i used this method in my RootViewController:
- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Verwaltung Information * selectedFormel = [listOfFormularies objectAtIndex:indexPath.row];
cell.textLabl.text = selectedFormel.nameFormel;
return cell;
}
The variable "nameFormel" is declared in VerwaltungInformation as NSString with property and synthesize.
But instead I get this error message:
[FormelViewController nameFormel]: unrecognized selector sent to instance
Terminating app due to uncaught exception 'NSInvalidArgument', reason : [FormelViewControlle nameFormel]: unrecognized selector sent to instance
I need some help! Since days I have been working on it but I can NOT find the error...If somebody need some more details to answer, please leave a comment.
Your problem is that [listOfFormularies objectAtIndex:indexPath.row] returns an FormelViewController object, not an object of type VerwaltungInformation.
You should check your data (i.e. the listOfFormularies array).

Unrecognized selector to an openfeint unlock achievement call

I use the call as it is supposed to be used, but it causes a crash.
//someId is a correct achievement ID
[OFAchievementService unlockAchievement:#"someId"];
and I get the following error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[OFAchievementService unlockAchievement:]: unrecognized selector sent to class 0x26f1c8'
I also get a warning
warning: 'OFAchievementService' may not respond to '+unlockAchievement:'
How is one supposed to call this function? This looks correct according to examples.
Try:
OFAchievementService *openfeint = [[OFAchievementService alloc] init];
[openfeint unlockAchievement:#"someId"];
[openfeint release];
instance methods begin with - class level methods begin with +.
With OpenFeint SDK 2.7+ try:
/* The following example shows how to unlock an achievement completely in one step without bothering to show a notification: */
[[OFAchievement achievement: achievementId] updateProgressionComplete: 100.0f andShowNotification: NO];
The following line just worked well enough for me (in OpenFeint SDK version 2.10i):
[[OFAchievement achievement:#"achievementID"] unlock];

iPhone: UILabel applying CGAffineTransformMakeRotation causing mysterious crash

In
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil parentController:(GameViewController *)myGameController{
Have a series of transforming labels like so:
deg90 = 1.570796326794897;
//....transforms
background.center = CGPointMake(160,230);
background.transform = CGAffineTransformMakeRotation(deg90);
BetLabel.text = #"test";
BetLabel.transform = CGAffineTransformMakeRotation(deg90);
That last line is crashing me with:
2010-04-13 21:04:47.858 Game[1204:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'
2010-04-13 21:04:47.893 Game[1204:207] Stack: (
864992541,
859229716, (lots of numbers)
But if I comment it out, I get the text changing fine.
Update: Uh oh, just did a test.. turns out the other transforms were on UIImageViews. Apparently rotating a label in this xib is causing the crash.
But in another file the transforms are working fine:
newprofileentry.transform = CGAffineTransformMakeRotation(1.570796326794897);
playerb0.transform = CGAffineTransformMakeRotation(1.570796326794897);
playerb1.transform = CGAffineTransformMakeRotation(1.570796326794897);
Tried substituting deg90 with the full float value, still the same crash.
Tried cleaning cache, restarting IB and Xcode, cleaning all targets. Program has been running fine until I just added these labels. Tried deleting the label, readding and reconnecting the Outlet, too.
Thanks for reading, hope someone has an idea about this.
Cheers!
I suggest moving the transforms out of initWithNib: It's possible that the you're trying to modify something that doesn't yet exist because the objects in the nib are still initializing.
You should also examine the nib file (in Interface Builder or with ibtool) to see if there is something scrambled with that particular label. To test that, you could swap out its order in the initialization with another label to see if the problem is with that particular label or whether it is with any label or object in the last position.
Posting more code in context would probably help.

A NSMutableArray is destroying my life!

IET ANOTHER EDIT (to increase strangeness)
EDITED to show the relevant part of the code
Hi. There's a strange problem with an NSMutableArray which I'm just not understanding...
Explaining:
I have a NSMutableArray, defined as a property (nonatomic, retain), synthesized, and initialized with 29 elements.
realSectionNames = [[NSMutableArray alloc] initWithCapacity:29];
After the initialization, I can insert elements as I wish and everything seems to be working fine.
While I'm running the application, however, if I insert a new element in the array, I can print the array in the function where I inserted the element, and everything seems ok.
However, when I select a row in the table, and I need to read that array, my application crashes. In fact, it cannot even print the array anymore.
Is there any "magical and logical trick" everybody should know when using a NSMutableArray that a beginner like myself can be missing?
Thanks a lot.
I declare my array as
realSectionNames = [[NSMutableArray alloc] initWithCapacity:29];
I insert objects in my array with
[realSectionNames addObject:[category categoryFirstLetter]];
although I know i can also insert it with
[realSectionNames insertObject:[category categoryFirstLetter] atIndex:i];
where the "i" is the first non-occupied position.
After the insertion, I reload the data of my tableView. Printing the array before or after reloading the data shows it has the desired information.
After that, selecting a row at the table makes the application crash. This realSectionNames is used in several UITableViewDelegate functions, but for the case it doesn't matter. What truly matters is that printing the array in the beginning of the didSelectRowAtIndexPath function crashes everything (and of course, doesn't print anything). I'm pretty sure it's in that line, for printing anything he line before works (example):
NSLog(#"Anything");
NSLog(#"%#", realSectionNames);
gives the output:
2010-03-24 15:16:04.146 myApplicationExperience[3527:207] Anything
[Session started at 2010-03-24 15:16:04 +0000.]
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 3527.
Still not understanding what kind of stupidity I've done this time... maybe it's not too late to follow the career of brain surgeon?
following an answer, i printed
NSLog(#"self=%x", self);
NSLog(#"self=%#", self);
NSLog(#"realSectionNames=%x", realSectionNames);
gives the exact same results in every function (from delegate or not).
NSLog(#"realSections = %#", realSectionNames);
prints well in my viewWillAppear, in the didSelectRowAtIndexPath, and crashes in viewForHeaderInSection. No threading, by the way...
So, without knowing what to do, I'm trying "things"... I changed all references of realSectionNames to self.realSectionNames
printing in the viewForHeaderInSection gives the following problem:
2010-03-24 16:01:44.067 myApplication[4104:207] numberOfSectionsInTableView result -> 1
2010-03-24 16:01:44.068 myApplication[4104:207] viewForHeaderAtSection
2010-03-24 16:01:44.068 myApplication[4104:207] self=3d13470
2010-03-24 16:01:44.068 myApplication[4104:207] self=<RootViewController: 0x3d13470>
2010-03-24 16:01:44.069 myApplication[4104:207] self.realSectionNames=3b12830
2010-03-24 16:01:44.070 myApplication[4104:207] realSections = (
<__NSArrayReverseEnumerator: 0x3b50500>
)
2010-03-24 16:01:44.070 myApplication[4104:207] *** -[__NSArrayReverseEnumerator length]: unrecognized selector sent to instance 0x3b50500
2010-03-24 16:01:44.071 myApplication[4104:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayReverseEnumerator length]: unrecognized selector sent to instance 0x3b50500'
2010-03-24 16:01:44.072 myApplication[4104:207] Stack: (
31073371,
2572170505,
31455291,
31024758,
30877378,
276908,
26404,
3227182,
4544033,
4551926,
4550923,
3267462,
3207973,
3249408,
25927,
3222086,
3205252,
459178,
30857920,
30854216,
39163413,
39163610,
2949039
)
What is a NSArrayReverseEnumerator??? And why is it being mean to me???
Note to everybody (and specially to self)...
I'm a dumb, dumb boy.
I was releasing an element which I inserted in the array.
Sorry for the questions, thanks for the answers...
When an application crashes, the Xcode Console will report the error that caused the application to crash. You will want to edit your question to include this error message, along with relevant source code, as this will help others answer your question.
I suspect your selected table row is trying to point to an index in the array, which does not exist. If so, you're trying to reference a part of the array that does not exist. This causes your application to throw an exception and quit.
Remember that an NSMutableArray can be initialized to a certain capacity, but until items are inserted, it does not actually hold any objects. The -initWithCapacity: method only sets aside a certain amount of memory, but there are no placeholders or nil entries for 1 through n indices.
1) Could we know the error message ? and the relevant part of the code ?
2) Here is the proper way to declare your array :
self.realSectionNames = [[NSMutableArray arrayWithCapacity:29];
I suspect your TableView's delegate isn't hooked up correctly, or is connected to an invalid object. Are any of your other delegate methods working? Try putting these at the top of didSelectRowAtIndexPath to check the pointer values:
NSLog(#"self=%x", self);
NSLog(#"self=%#", self);
NSLog(#"realSectionNames=%x", realSectionNames);