why crash this code at boundingRectWithSize? - objective-c

- (CGSize)sizeOfLabel:(UILabel *)label withText:(NSString *)text {
CGSize maximumLabelSize = CGSizeMake(308,9999);
UIFont *font=[UIFont systemFontOfSize:14];
CGRect textRect = [text boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:#{NSFontAttributeName:font} context:nil]; // CRASH HERE
return textRect.size;
}
**the error message is:**
2014-06-16 14:55:07.783 OrgBeac[2931:60b] -[Message boundingRectWithSize:options:attributes:context:]: unrecognized selector sent to instance 0x17557a70
2014-06-16 14:55:07.787 OrgBeac[2931:60b] \*\*\* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Message boundingRectWithSize:options:attributes:context:]: unrecognized selector sent to instance 0x17557a70'
\*\*\* First throw call stack:
(0x2e6f4fd3 0x38f6dccf 0x2e6f8967 0x2e6f7253 0x2e6f84f8 0x575d5 0x579e7 0x31020a2b 0x30fe569f 0x30fe73fd 0x30fe7351 0x30fe6f45 0x56f37 0x2f0e56d1 0x39324cef 0x393222ad 0x39321319 0x2f0e3cb9 0x2f0e3f41 0x2f0e40b7 0x2f0e41b5 0x5674d 0x2f033fc3 0x2f033f07 0x2f033e21 0x2e35b0e7 0x2e359cf7 0x2e628941 0x2e2f16bb 0x2e2f1579 0x2e2f140d 0x2e6c025b 0x2e6bf72b 0x2e6bdf1f 0x2e628f0f 0x2e628cf3 0x33581663 0x30f7416d 0x55283 0x3947aab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

The object text that you are passing in needs to be an NSString but it is a Message object.
I'm guessing that wherever you are calling this from you are doing something like...
[someObject sizeOfLabel:myLabel withText:message];
When in fact what you meant is...
[someObject sizeOfLabel:myLabel withText:message.text];

Related

Crash when setting attributes dictionary of UIBarButtonItem

I have the following code:
UIFont * applicationBolFontOfSize26=[fontsSuperclass returnApplicationMainFontOfSize:26.0f];
[self.settingsButton setTitleTextAttributes:#{ NSFontAttributeName : applicationBolFontOfSize26 } forState:UIControlStateNormal];
where font superclass method is defined as:
+(UIFont *)returnApplicationMainFontOfSize:(CGFloat)floatSize {
return [UIFont fontWithName:#"HelveticaNeue-Regular" size:floatSize];
}
but the self.settingButton setTitleText... crashes with error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
Why?
There is no font named "HelveticaNeue-Regular" so your font is nil. Use [UIFont fontWithName:#"HelveticaNeue" size:floatSize] for the regular Helvetica Neue font.

assigning values in NSArrays

Objective C gives me a run-time error for the indicated line of code
-(void) play: (int)i at: (int)j {
if ([self.board[i][j] isEqualToString:#""]){
if (xplays) {
self.board[i][j] = #"x"; //<-----HERE
}
else
self.board[i][j] = #"x";
}
xplays = !xplays;
}
board is a property. The error message is
[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x7123120
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x7123120'
Do I need to use C-arrays for this kind of assignment?
You should be using an NSMutableArray.

Problems passing data between different classes with a method

I have this in a class:
NSString *globalMidiData = #"30a0a00\n";
switch (IndicatorCheckNXT) {
case 1:
[testRobot checkTestRobot:globalMidiData];
break;
default:
break;
}
And in another class I have this:
-(void) checkTestRobot: (NSString *)midiDataGlobal{
bool pressed;
bool pressed2;
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
}
And I got this message:
-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0
2012-11-23 20:45:31.755 Exemple1[477:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0'
What I am doing wrong?
Obviously you send checkTestRobot to the wrong object. testRobot seems to point to the AppDelegate and not to an instance of your class.
Also you should replace this:
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
with:
NSString *miawmiaw = [midiDataGlobal copy];

Why CCLabelAtlas[1] refuses to update?

I have 7 CCLabelAtlas labels declared in .h file like this CCLabelAtlas *numberStat[7]. Then I then initialized them in a for loop in .m file:
for (int i = 1; i <=7; i++) {
NSString* statName = [NSString stringWithFormat #"Number %d", i];
numberStat[i] = [[CCLabelAtlas labelWithString: [self loadThisValue:statName] charMapFile:#"digitalNumbers.png" itemWidth:26 itemHeight:37 startCharMap:'0'] retain];
[self addChild: numberStat[i]];
}
The problem comes when I try to update the label. I can update from 2 to 7 just fine, but when I try to update numberStat[1]'s string (numberStat[1].string = #"111";), it crashes. The exact same code works for 2-7.
Here's the crash log:
-[CCSprite setString:]: unrecognized selector sent to instance 0x897cbd0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CCSprite setString:]: unrecognized selector sent to instance 0x897cbd0'
One possibility is that somewhere in your code, numberStat[1] is being over-released, and by the time you come to assign a string to it, a CCSprite has moved into the memory that it occupied.

Error saving to iOS keychain using KeychainItemWrapper

I get an error every time I try to store data into the keychain
The error comes from the dictionaryToSecItemFormat method at these lines
NSString *passwordString = [dictionaryToConvert objectForKey:(id)kSecValueData];
[returnDictionary setObject:[passwordString dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecValueData]'
The error is
I'm calling the KeychainItemWrapper methods like this
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:#"credentials" accessGroup:nil];
[keychain setObject:username forKey:kSecAttrAccount];
[keychain release];
The error is
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[NSConcreteData dataUsingEncoding:]: unrecognized selector sent to instance"
dataUsingEncoding is a method from the NSString class, make username a NSString.