开发者

Problem passing frame from setting.plist

I have defined frame in my settings.plist and accesing it in my class as a string while passing it gives an error:

Here's the c开发者_运维问答ode:

NSString * frame = [selectable objectForKey:@"Frame"]; 
[self selectButtons:@"Select." andFrame:frame andValue:goal];


-(void)selectButtons:(NSString *)text andFrame:(NSString *)frame andValue:(int)goal
{

    UIColor * c = [UIColor clearColor];
    UIFont * font = BUTTON_TITLE;
    UIColor * f = DESC_Color_White;
    select = [ApplicationHelpers buttonWithTitle:text andBgColor:c andTitleColor:f andTitleFont:font];
    CGRect frame1 = frame; -------->>>>>> gives error here
    select.frame = frame1;

    UIImage * buttonImage = [UIImage imageNamed:@"scneariosButtonSmall1.png"];
    UIImage * strechableButtonImage = [buttonImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [select setBackgroundImage:strechableButtonImage forState:UIControlStateNormal];
    [select addTarget:self action:@selector(selectClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:select];

}

Please give me some hint on this???

Thanks,


An NSString cannot be implicitly converted between a CGRect. You need to use functions like NSStringFromCGRect and CGRectFromString to do the conversion.

CGRect frame1 = CGRectFromString(frame);

...

// when you need to save the CGRect:
NSString* frameString = NSStringFromCGRect(frame1);


You can't just assign a string to a CGRect variable and expect that it works. You have to convert one type into the other. Depending on what format your frame string is in, you might be able to use the CGRectFromString() function (use NSStringFromCGRect()) to create a corresponding string from a CGRect. Or you have to parse the string manually yourself.

Or, perhaps even better, wrap your frame value in an NSValue with +[NSValue valueWithCGRect:] and -[NSValue CGRectValue].

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜