Odd error (UITextSelectionView) while calling a method? - ios

I'm facing a problem while calling a method and I don't know how figure it out.
Basically, during the main menu, I want to call a SKNode showing a tutorial part. The code is the following:
- (void)didMoveToView:(SKView *)view
{
...
if ([[GameData sharedData] openingTutorial]) { // Checks if the menu needs the tutorial
[_tutorialObj performSelector:#selector(runTutorialWithStep:)
withObject:[NSNumber numberWithInt:8]
afterDelay:3.0
];
}
}
When the method didMoveToView: is called (even before waiting the 3 seconds for the runTutorialWithStep:), I got this error:
[UITextSelectionView name]: unrecognized selector sent to instance 0x1576e6c0
2014-10-14 11:01:19.430 [406:130379] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextSelectionView name]: unrecognized selector sent to instance 0x1576e6c0'
The odd thing is that in the previous class I use the same tutorial's action in the didMoveToView: and it's working right. But...
Thing is getting more strange here!!!
If I use an intermediary method for this calls:
- (void)didMoveToView:(SKView *)view
{
...
[self performSelector:#selector(intermediaryMethod)
withObject:nil
afterDelay:3.0
];
}
- (void)intermediaryMethod
{
[_tutorialObj performSelector:#selector(runTutorialWithStep:)
withObject:[NSNumber numberWithInt:8]
afterDelay:0.0
];
}
Everything works without issues. I don't want to avoid the problem but solve this. Any advices?

The error says it all. You try to send a 'name' message to object that doesn't implement it (UITextSelectionView). Since your second take works the cause is either in
[[GameData sharedData] openingTutorial]
method or before this call. Search for objects calling 'name' and check if it's the UITextSelectionView in question.
That or maybe you have weak reference to general view object and during those three seconds before calling runTutorialWithStep you reassign it to object that implements 'name' message.

Ok, I solved the problem.
I added a breakpoint for every exception and I realized that the issues was due to an other class (the only one with UITextView).
Basically I removed the text field from its parent ([self removeFromParent]) by my own once I did not need it anymore.
I suppose the error was fired during the deallocation 'cause the program can't find the UITextView. I managed to remove this statement and everything works right.
Actually I still have doubts because I don't understand why this exception is throw only if I call the [_tutorialObj runTutorialWithStep:] method.

I found the way to fix it.
UITextView *textView = .....
textView.selectable = NO;

Related

NSInvalidArgumentException', reason: '-[__NSCFConstantString sizeWithTextStyle:]: unrecognized selector sent to instance 0x170838 [duplicate]

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!

How can I find the sender of an unrecognized selector in LLDB?

I'm getting an "unrecognized selector" error that is confusing me.
I know that I can "po" the pointer in LLDB to find out about the receiver. But is there a way to deduce which object is sending this message?
Thanks!
The command bt in the debugger will show you a backtrace (stacktrace), which should give you the class that initiated the message somewhere in that output.
Backtrace doesn't always help if you're dealing with multiple threads - you end up with the backtrace of the exception handler on the main thread which isn't necessarily the one that cause the error.
However, since you know that the particular selector doesn't exist for a particular class, you can cheat a little by using a category to add the selector to the class, then just stick a breakpoint on it.
For example, for this error:
-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x10004fb0
we know that something's trying to call "NSDictionary" with "isEqualToString". So, add this at the end of any file you like, outside any other "#implementation" blocks:
#implementation NSDictionary(debug)
- (BOOL)isEqualToString:(NSString*)theString {
return FALSE;
}
#end
Stick a breakpoint on this, re-run your code and you will get a genuine stack trace. Don't forget to remove the category once you've found the error!

Call controller method from different thread in iOS

I'm trying to call this method from a music-rendering function that is run in a different thread. The method is inside InstrumentGridViewController.
- (IBAction)stopPlayback:(id)sender{
[self stopToneUnit];
}
This is how I'm calling the method:
dispatch_async(dispatch_get_main_queue(), ^{ [InstrumentGridViewController stopPlayback: nil]; } );
But I'm getting this warning:
Class method `+stopPlayback` not found (return type defaults to `id`)
And when I try to run:
erminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[InstrumentGridViewController stopPlayback:]: unrecognized selector sent to class 0x13e50'
I'm sure the method is there so I really don't see why this is happening.
EDIT: H2CO3 said I should call the stopPlayback method on the currently running instance. Any ideas how I could do that?
Because the method is implemented as an instance method and not as a class method. You must call it on an object of class InstrumentGridViewController, and not on the class itself.

Objective-c program crashes when trying to remove objects from superview

Bellow is the code i am calling when i press a button. The button will call the method bellow. But i get a "unrecognized selector sent to instance" error. What am i doing wrong? The objects have been declared in another method before this one is called. I have also tried hiding the buttons but they also crash. Someone please help.
-(void) clearControlPannel{
[buttCheck removeFromSuperview];
[buttBet removeFromSuperview];
[buttCall removeFromSuperview];
[buttRaise removeFromSuperview];
[buttFold removeFromSuperview];
[betLabel removeFromSuperview];
[betSlider removeFromSuperview];
}
The crash is:
Thread 1: EXC_BAD_ACCESS" on the [buttCheck removeFromSuper]; line
-[__NSCFDictionary removeFromSuperview]: unrecognized selector sent to instance 0x686b020 2012-06-24 19:08:12.175
HeadsUp[59630:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary removeFromSuperview]: unrecognized selector sent to instance 0x686b020'
unrecognized selector sent to instance
error is due to the fact that the runtime is not able to find the method that will respond to that specific action. In other words, it's not able to map the name of your method (the selector) with its implementation.
So, if you have a method that accept no parameter like yours
- (void) clearControlPannel {...}
the selector will be only clearControlPannel.
Otherwise, if you have specified a parameter for that method (e.g. like the sender, the UIButton in this case) like
- (void) clearControlPannel:(id)sender {...}
the selector would be clearControlPannel:. Pay attention to :.
If you provide more details we could help you.
EDIT
Just for pointing you in the right direction.
If you have used – addTarget:action:forControlEvents: on a UIButton instance you have to check two things.
First, did you set up the target correctly? The target is the object to which the action will be redirected.
Second, did you set up the right selector for that action?
Here an example:
[myButton addTarget:self action#selector(mySelector:) ...];
where
- (void)mySelector:(id)sender {...}
If the class where you have implemented that button will also respond to that action use self, otherwise you need to inject some other instance that will respond for that action.
Check wheather you are releasing the button which you are pressing.

Program crashed in iOS5 and normal in iOS4?

My game created in cocos2d 0.99.5.I tested it and released in App Store already.
After I updated my iPhone from iOS4.3.3 to iOS5.0, my game crashed so frequent.
* Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection <__NSArrayM: 0x668a540> was mutated while being enumerated.'
* First throw call stack:
(0x30bed8bf 0x37d921e5 0x30bed3e3 0x5cd1 0x2f837 0xa577b 0xae245 0xcc29d 0xcdfed 0x322ee423 0x322ee379 0x358d3f93 0x31e81891 0x30bb6f43 0x30bc1553 0x30bc14f5 0x30bc0343 0x30b434dd 0x30b433a5 0x33771fed 0x32bb5743 0x2c65 0x2bf8)
terminate called throwing an exception
This crash broken memory stack.After I added "objc_exception_throw" breakpoint. I found crash happening in for{} NSArray loop.
I don't know why this crash only happened is iOS5.This test of game is ready for new version and new content.I can't resolve this problem and feel dejected.
Could someone help me?
====================================
update(11/3/11):
NSMutableArray *monsterArray; // monsters information
[gameObject schedule:#selector(gameSchedule:) interval:1.0/30]; // schedule for everything update
- (void) gameSchedule:(ccTime)_dt
{
...
for ( Monster *mon in monsterArray ) // here causing crash
{
...
// check every monster state
}
}
I don't know thread module of cocos2d thoroughly.In my game project, there are some CCAction do sequence action:
id action = [CCSequence actions:
...,
[CCCallFunc actionWithTarget:self selector:#selector(doSth:)],
nil];
[object runaction:action];
- (void)doSth:(id)_sender
{
//some selector modified object value in monsterArray
//some selector deleted or added object in monsterArray
}
Whether cocos2d creat a new thread for doSth: and causing the crash ?
There are many selector which did these action(modify, delete and add) in my game project.
How can I resolve this problem?
===================================================================
update(11/4/11):
#Amorya
I checked Documents about NSCopying protocol.
[monsterArray copy] return a new NSMutableArray.New object in [monsterArray copy] run actions which like CCMove\CCSequence\CCJump will causing correct process?I don't understand.Please explain it.
#Brad Larson
I added a Symbolic breakpoint "objc_exception_throw" and find out the for{} NSMutableArray loop caused the crash.
Change this line
for ( Monster *mon in monsterArray )
to
for ( Monster *mon in [monsterArray copy] )
You're not allowed to modify an array while iterating over it using fast enumeration (as LearnCocos2D mentioned in a comment). Copying the array is the simplest way to fix that without changing your code's logic.
If you're not using ARC, you'll also need to throw an autorelease in there.

Resources