开发者

Set a value for CGRect.frame.size from a NSDictionary

I generate a dictionary from a JSON string, and one of the value of the dictionary aims to be used as the height of a 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 get the following error:

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

I'm newbie in Ob开发者_运维技巧jective C I don't know if this has something go see with pointers, casting, please give me some light.


you can take particular value in string i.e,

NSString *str=[arr valueForKey:@"location"];
CGRect rect9 = CGRectFromString(str);

This will convert to CGRect so that you can use it in the place of Frame


You might want to try CGFloat *height = [[dic valueForKey:@"intHeightPixels"] floatValue]; In dictionaries there is only object (here it's a NSNumber)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜