CellData *cellData = [self.tableElements objectAtIndex:indexPath.row];
NSLog(#"name is %#",[self.tableElements objectAtIndex:1]);
cell.lbl.text = cellData.name;
here am getting the error when i able to access my NSObject class variables.
self.tableElements is an array with elements parsed.
cellData is not what you think it is, you think it is a CellData object but it is actually an NSArray, double check what self.tableElements is holding.
Related
This is a continuation question I had from a post yesterday: Initializing NSMutableDictionary
(It's probably a stupid question, but I don't see what I'm doing wrong.)
I liked the idea of just having "All" listed in my TableView that pops up when the filter button is pressed in order to indicate no filter applied. I get my data from my model class sorted correctly into an NSMutableArray like so:
NSArray *anArray = [dmgr.CategoryDictionary allKeys];
self.CategoriesArray = [anArray sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
[self.CategoriesArray insertObject:#"All" atIndex:0]; // line causes crash
But I want to add the "All" option to the CategoriesArray to show in the UITableView. When I try to run it, it crashes at that line because of
NSArrayI insertObject:atIndex:]: unrecognized selector sent to instance 0x59baba0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI insertObject:atIndex:]: unrecognized selector sent to instance 0x59baba0'
Any help would be appreciated. Thanks!
sortedArrayUsingSelector: returns an immutable array which is why you can't add to it. Do this to get a mutable copy.
self.CategoriesArray = [NSMutableArray arrayWithArray:[anArray sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)]];
It seems CategoriesArray is actually a NSArray instance. From Apple's doc :
-(NSArray *)sortedArrayUsingSelector:(SEL)comparator;
I would like to do this:
I have a dictionary like this:
[myMutableDictionary setValue:myNSNumber forKey:#"myKey"];
myNSNumber is an NSNumber.
myCell.label.text = [self.myMutableDictionary objectForkey#"myKey"];
I have an error when I assign the number stored in my dictionary to my label in myCell.
The error is:
je suis la 2011-05-02 15:01:01.264 []
-[NSCFNumber isEqualToString:]: unrecognized selector sent to instance
0x225d00 2011-05-02 15:01:01.319 []
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NSCFNumber isEqualToString:]:
unrecognized selector sent to instance
0x225d00'
NSNumber is not an NSString and the text of the label needs to set to an NSString.
NSNumber *num = (NSNumber*)[self.myMutableDictionnary objectForkey#"myKey"];
myCell.label.text = [num stringValue];
Here you can do it by 2 ways
first is myCell.label.text = [[self.myMutableDictionnary objectForkey#"myKey"] stringValue];
second is myCell.label.text = [NSString stringWithFormat:#"%d",[self.myMutableDictionnary objectForkey#"myKey"]] ;
i am getting json data from this link
now i want data from "html_instructions": part
NSDictionary *result = [stringtext JSONValue];
NSLog(#"here");
NSArray *resultarr = [result objectForKey:#"routes"];
NSString *string;
for(NSDictionary *di in resultarr){
NSLog(#"for loop");
string = [[di objectForKey:#"legs"] objectForKey:#"steps"];
}
but after printing "for loop" in console it is throwing an exception
2011-05-20 16:16:26.997 speedymap[759:207] -[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x62a7d60
2011-05-20 16:16:26.999 speedymap[759:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x62a7d60'
please help me
i want html_instructiuons field value
Check if resultarr and di really contains anything or not.
NSDictionary *result = [stringtext JSONValue];
NSLog(#"here");
NSArray *resultarr = [result objectForKey:#"routes"];
CFShow(resultarr);
NSString *string;
for(NSDictionary *di in resultarr){
CFShow(di);
NSLog(#"for loop");
NSArray *tempArr = [[di objectForKey:#"legs"] objectForKey:#"steps"];
}
http://jsonviewer.stack.hu/#http://maps.googleapis.com/maps/api/directions/json?origin=delhi&destination=noida&waypoints=&sensor=true
Check the viewer and set the values accordingly. [di objectForKey:#"legs"] returns an array. the first object of that array is a dictionary which has the key steps. But that too returns another array.
after nsXml pasring value of my NSMutable array AB
=\n\n\n\thttp://xyz.com/uploads/resto_6298__20091209#1621_250.JPG\n\thttp://xyz.com/uploads/resto_6298__200912099_2_250.JPG\n"
now i am doing this to make this url working
NSString *sw=AB;
NSArray *strings = [sw componentsSeparatedByString: #"\n\t"];
NSLog(#"what I have %#",strings);
but my app always crash and i am getting this error
[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1b28b0
2010-10-05 10:17:31.382 Wat2Eat[2311:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1b28b0'
how to parse this AB so that i can extract exact URL
NSString *sw=AB;
AB is an NSMutableArray?
the compiler should print a warning if you try to do this. You tried to assign an NSArray to an NSString. This will not work.
Did you mean NSString *sw = [AB objectAtIndex:foo]; ?
StringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
//Regex Out Artist Name
//NSString *regEx = ;
NSArray *iTunesAristName = [stringReply componentsMatchedByRegex: #"(?<=artistname\":\")([^<]+)(?=\")"];
if ([iTunesAristName isEqual:#""]) {
NSLog(#"Something has messed up");
//Regex Out Song Name
}else{
NSLog(iTunesAristName);
}
NSLog(iTunesAristName);
[stringReply release];
I just keep getting this error ?
2010-09-29 21:15:16.406 [2073:207] *** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800
2010-09-29 21:15:16.406 [2073:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800'
2010-09-29 21:15:16.407 [2073:207] Stack: (
please help its driving me crazy
The first argument to NSLog is supposed to be a format string. You're passing an NSArray. When the function tries to treat your array as a string, you get that error. Instead, use NSLog(#"%#", iTunesAristName);.
Chuck has answered your question, but I've noticed something else that is problematic.
NSArray is an array, not a string, so [iTunesArtistName isEqual:#""] will never return true, because they are different classes. Even if iTunesArtistName was a string, it should be compared using the isEqualToString: method, not isEqual:.
If you want to extract only the artist's name, you might be able to do this:
NSArray *matches = [stringReply componentsMatchedByRegex: #"(?<=artistname\":\")([^<]+)(?=\")"];
if ([matches count] == 0)
{
NSLog(#"Could not extract the artist name");
}
else
{
NSString *iTunesArtistName = [matches objectAtIndex:0];
NSLog(#"Artist name: %#", iTunesArtistName);
}
I see you're using RegexKitLite, make sure you import libicucore.dylib, i was getting the same error until i imported that library.