开发者

Setting an objectAtKey string from NSDictionary to an NSString in separate class

I have got information from a URL(JSON); I easily populate my tableView with the text from my dictionary [aCategory objectAtKey:@"na开发者_StackOverflow中文版mes"] for the cell labels. Now, based on the cell name (category), I want to display another table that will ask for the last URL in order to grab the rest of the text, based on that category.

So, i want an ID which is in [aCategory objectAtKey:@"ID"] to save to a string and put in the URL in the next viewController. I am currently trying to generate it using the auto-generated set method to populate the NSString *ID in the target viewcontroller; when i call [newView setID: [aCategory objectAtKey:@"ID"].

My new view controller's NSString ID says it is not empty, but when i try to check to see if it is indeed "1" or "2" i get something like /p2002 or something. However, in the original class, if i say cell.detailLabelText.text = [aCategory objectAtKey:@"ID"];, the labels correctly show "1" "2" "3".."14" etc....

SO, how can i get that ID from that key into my other viewcontroller class?

I Know it is a valid NSCFString cause i tested it both with isClass AND with the cell's detailLabelText.


I need more detail to be sure about this, but a couple of notes...

NSString is what is called a class cluster, which basically means it is actually a collection of several class different classes that the underlying framework switches between...this means if you are checking it with

isKindOfClass:

you might not be getting the results you are expecting. Check the documentation for isKindOfClass: in NSObject.

However, I am not sure if there is anything to worry about. The reason you are seeing something like '\p2002' (Could the first letter be a u?) could just be the current underlying representation of the string. Sometimes, when the device holds the content of the string in memory, it does not look exactly like "1" or "2". It doesn't mean that there is a problem: it just means that, a deeper level, the way the string is being held in memory is in different form. That is why your label might say "2" but the variable, when you check it in memory, looks different.

(I am guessing that, since you are handling JSON, the string is encoded in a form called UTF-8.) The point is, nothing may wrong at all.

The real question is, is your new view controller loading correctly or not? Maybe in the viewDidLoad: method of your new view controller, if you run something this line:

NSLog(@"%@", stringID);

This will print the value of stringID to the console. If this number is the same as the number of the table cell's label in the previous view controller, everything should have been passed correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜