0

I fetch values from dictionary and need to display in UITableView, but everything works fine.

On some spot it stops running and shows thread

-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xbfa7670

The code below, which I used to fetch value..

[NSString stringWithFormat:@"%@",[[pageCat1 valueForKeyPath:@"img3"] objectAtIndex:indexPath.row]]

My values are fetched properly in dictionary but lags to display it?

pageCat (
    {
    img3 = "http://xxx.in/images/page_cat_img/75x75/4.jpg";
    name = "PVC Flexible Wires";
    page =         (
                    {
            id =                 {
                text = 1;
            };
            img4 = "http://xxxx.in/images/page_img/75x75/1.jpg";
            name = "SINGLE CORE FLEXIBLE WIRES ABOVE 6 SQMM";
        },
                    {
            id =                 {
                text = 72;
            };
            img4 = "http://xxx.in/images/page_img/75x75/72.jpg";
            name = "SINGLE CORE FLEXIBLE WIRES BELOW 6 SQMM";
        }
    );
},
    {
    img3 = "http://xxx.in/images/page_cat_img/75x75/3.jpg";
    name = "Bare Copper Wires";
    page =         {
        id =             {
            text = 29;
        };
        img4 = "http://xxx.in/images/page_img/75x75/29.jpg";
        name = "Tinned Copper Fuse Wires";
    };
},
    {
    img3 = "http://xxx.in/images/page_cat_img/75x75/48.jpg";
    name = "Properties of Wire";
    page =         {
        id =             {
            text = 85;
        };
        img4 = "http://xxx.in/images/page_img/75x75/85.jpg";
        name = "Wires - Normal, HR - PVC, FR, FRLS & Zero Halogen";
    };
}

)

Actually look at the log value, it has array and set of values.. i can't find whether it is in what form..

Can anyone help me to find the solution??

Thanks, Yazh

4
  • what is the actually response can you please show us that you are trying to get value. Commented Jun 5, 2014 at 10:58
  • In tableview, on clicking a cell displays its sub category.. Thread SIGART is show on my code which i mention above. Commented Jun 5, 2014 at 11:00
  • sir i said actual output of responce pageCat1 Commented Jun 5, 2014 at 11:07
  • pageCat { img3 = "xxxx.in/images/page_cat_img/75x75/38.jpg"; name = Chennai; page = { id = { text = 129; }; img4 = "xxxx.in/images/page_img/75x75/129.jpg"; name = "Consultants In Chennai"; }; } while log pagecat it shows array like this.. Am Miss not sir.. Commented Jun 5, 2014 at 11:17

4 Answers 4

2

it looks like [pageCat1 valueForKeyPath:@"img3"] returns a NSString and not a NSArray like you expect

make sure that it returns a NSArray before applying objectAtIndex:

it seems that pageCat1 is a NSArray so you need to write something like:

NSString *path = pageCat1[0][@"img3"];

...
Sign up to request clarification or add additional context in comments.

Comments

1

As the error already tells, [pageCat1 valueForKeyPath:@"img3"] returns a NSString and you are calling objectAtIndex: on it which is not recognized for this class. Obviously, pageCat1 differs from what you expected.

Try NSLog(@"%@", pageCat1); to see what it really looks like.

// Edit

pageCat1 (as seen in your update) is an NSArray that contains items of type NSDictionary. What you really want to do is NSString *imgURL = [[pageCat1 objectAtIndex:indexPath.row] objectForKey:@"img3"];

Explanation: 1. [pageCat1 objectAtIndex:indexPath.row] returns a NSDictionary 2. [__dictionary__ objectForKey:@"img3"] returns the NSString containing your image URL

Comments

1

Actually I used XML data, for that i used third party to parse data. Its all of third party which parsed alternate data as array and other as non-array. Finally I check the array with

isKindOfClass

and convert it into array. Therefore my problem in app solved. :-)

Thanks to all who help me..

Comments

0

Please try this one:

//Assuming json is your main dictionary    

NSDictionary *pageCat = [json objectForKey:@"pageCat"];
    NSMutableArray *array = [[pageCat valueForKey:@"img3"]mutableCopy];
    NSLog(@"Value=%@", [array objectAtIndex:indexPath.row]);

9 Comments

Can you post here the NSDictionary value please. NSLog(@"pageCat1=%@",pageCat1);
Please check is it working: NSDictionary *pageCat = [json objectForKey:@"pageCat"]; NSMutableArray *array = [[pageCat valueForKey:@"img3"]mutableCopy]; NSLog(@"Value=%@", [array objectAtIndex:indexPath.row]);
Okay convert it into NSMutableArray form. Try with this one: NSMutableArray *array = (NSMutableArray *)[pageCat valueForKey:@"img3"]; and after that first print array and if it works fine then try with objectAtIndex.
yes. Juz look at the log values, it is in different format. so only i can't access values. Can anyone tell me how to fetch it..
can you write here, what it prints NSLog(@"array=%@",array);
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.