iPhone – Set a value from nsDictionary for cgrect.frame.size

I generate a dictionary from a JSON string, and the value of one of the dictionary is intended to be used as the height of the WebView object.

NSDictionary *dic = [jsonParser objectWithString:response];
CGFloat *height = [dic valueForKey:@"intHeightPixels"];
CGRect frame = webView.frame;
frame.size.height = height;
webView.frame = frame;

In line 2, I receive the following error:

Initializing ‘CGFloat’ (aka float) with an expression of incompatible type’id’.

I am a newbie in Objective C. I don’t know what is there to look at pointers, casting, please Give me some highlights.

You may want to try CGFloat * height = [[dic valueForKey:@” intHeightPixels”] floatValue]; There are only objects in the dictionary (here NSNumber)

I generate a dictionary from a JSON string, and the value of one of the dictionary is intended to be used as the height of the WebView object.

NSDictionary *dic = [jsonParser objectWithString:response];
CGFloat *height = [dic valueForKey:@"intHeightPixels"];
CGRect frame = webView.frame;
frame.size.height = height;
webView.frame = frame;

In line 2, I receive the following error Error:

Initializing’CGFloat’ (aka float) with an expression of incompatible type’id’.

I am Newbie in Objective C I don’t know what is there to look at pointers, casting, please give me some highlights.

You may want to try CGFloat * height = [[dic valueForKey:@”intHeightPixels”] floatValue]; There are only objects in the dictionary (here NSNumber)

Leave a Comment

Your email address will not be published.