RegexKitLite & Unrecognized Selector Sent to Instance Error - iphone

I am not sure why the following line:
addDetails.Address = [addDetails.Address stringByReplacingOccurrencesOfRegex:#" +" withString:#" "];
causes an "Unrecognized Selector Sent to Instance" error, closing my iPhone App in my Simulator(XCode).
What's wrong with my code?

stringByReplacingOccurrencesOfRegex:withString: is a NSString category defined in RegexKitLite.h of RegexKitLite lib.
Looks like you haven't add this category into your project properly see:
http://regexkit.sourceforge.net/RegexKitLite/#AddingRegexKitLitetoyourProject
or addDetails.Address is not NSString.

Related

Error while running iPhone App Help - __NSCFConstantString error meaning

Could someone please tell me what this means:
2013-02-08 11:19:49.394 xxxxx[10545:907] set selected tab with tag 3
2013-02-08 11:19:49.560 xxxxx[10545:907] did select item
2013-02-08 11:19:49.562 xxxxx[10545:907] tab clicked
2013-02-08 11:19:49.566 xxxxx[10545:907] will show view controller MoreViewController
2013-02-08 11:19:49.567 xxxxx[10545:907] will show other VC
2013-02-08 11:19:49.579 xxxxx[10545:907] -[__NSCFConstantString offImage]: unrecognized selector sent to instance 0x21994c
2013-02-08 11:19:49.580 xxxxx[10545:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString offImage]: unrecognized selector sent to instance 0x21994c'
I just tried modifying some code, however the modifications did not work. So pressed z and undid everything I modified, but now I get this error.
The "unrecognized selector sent to instance" error always means one thing: you are calling a method on an instance that does not support it. In this particular case, you have a line in your code that looks like this:
[someObject offImage];
On this line, someObject is an instance of string, which does not have an offImage method.
This problem could be caused by passing an object of a wrong type to some other method:
[someTarget objectWithOffImage:#"Hello"];
The method could be expecting an object that responds to offImage, but you are passing it a string.
Finally, you may be trying to invoke a method in a category, but you forgot to import the header file for the category.
You are sending the message -offImage to an instance of NSString which does not have a method with that name. Alter your code so that -offImage is sent to the right kind of object

Exception throwing JSON supporting program in iphone

I downloaded JSON files. I added these files in project directory. But when I am runnig program I am getting an error which is...
-[__NSCFDictionary
JSONRepresentation]: unrecognized
selector sent to instance 0x6003d50
* Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[__NSCFDictionary
JSONRepresentation]: unrecognized
selector sent to instance 0x6003d50'
* Call stack at first throw:
I imported header file #import "JSON/JSON.h" and I wrote jsocn code in viewDidLoad function which is like below...
NSDictionary *requestData = [NSDictionary dictionaryWithObjectsAndKeys:
#"grio", #"username",
#"hellogrio", #"password",
nil];
NSString* jsonString = [requestData JSONRepresentation];
NSLog(#"%#", jsonString);
Kindly help me.
Thanks in advance.
I am guessing you are using json-framework. You probably forgot to add -all_load to the linker flags. See this question for more details.
It's not clear from your question which JSON implementation you're using, but the error means that you're sending the JSONRepresentation message to an NSDictionary. The dictionary does not understand the message and raises an exception.
It seems that either you're not using the JSON library correctly or that you have not installed it correctly in your project.

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

NSURL Exceptions

I am trying to grab a path value from an array for an NSURL to set an icon in my app. I get an
NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x5622590.
If I use an nslog I get the expected output:
NSLog(#"%#",[[wforecast.wicons objectAtIndex:0]valueForKey:#"nodeContent"]);
Which gives me:
Im setting the value as follows
NSURL *urlpath;
NSString *urls = [[wforecast.wicons objectAtIndex:0] valueForKey:#"nodeContent"];
urlpath = [NSURL URLWithString:(NSString *)urls];
I appreciate this is a longwinded way of doing things but I was trying to break up the individual components to find out what was going wrong but I am at a loss!
You have essentially the same problem as this other questioner had. You passed an object that is not an NSString where you needed to pass an NSString.
Use the debugger to determine exactly where the exception occurred. If you haven't done this, I wouldn't be so sure that the code you showed is what caused it; the debugger will tell you where the exception occurred with no room for doubt.
Once you've found where the exception occurred, you can examine the object that you passed, and look back at where you got it from. You need to fix either how you retrieve the string or how you stored it in the place you're now getting it from.

trying to obtain an objects title variable gives unrecognized selector sent to instance

I have an object which holds a title and an indexReference. I save the object to an array and that works correctly.
I then try to load from the array and populate the tableview.
I use this code.
//fill it with contents
SavedFav *temp = [tableViewData objectAtIndex:indexPath.row];
cell.textLabel.text = temp.title;
I then get an error as the following
2010-07-01 15:42:46.386 Daily Quote[1308:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString title]: unrecognized selector sent to instance 0x23f6688'
What is causing this problem?
Thanks in advance.
"temp" is a string obviously, so it's too many answers to give, either you filled tableViewData with strings and trying to obtain title from a string (which is unrecognized) or you have problem with memory there, without seeing more code it's hard to say.
however try
cell.textLabel.text = temp;
and check what's inside, that will give you a good lead.