我的核心数据模型中有一个变量设置为浮点类型,名为"speech1Size“。我尝试使用该变量来设置UILabel的字体大小,但每次尝试都会遇到错误。
运行以下示例将返回此错误:
“找不到方法'+fontWithSize:‘(返回类型默认为'id')”
// first I get the value
NSNumber *fontSize = [detailViewController.detailItem valueForKey:@"speech1Size"];
// try to set the UILabel's font size
detailViewController.speech1Label.font = [UIFont fontWithSize:fontSize];我已经尝试了各种其他方法,比如强制转换为浮点数,但这会返回一个错误,到目前为止,这似乎是最接近的。我意识到我错过了一些东西simple...Thank你的时间!!
发布于 2011-08-27 03:13:09
fontWithSize方法是一个实例方法,您正尝试将其用作类方法。也许你想使用+fontWithName:size:。
此外,size参数应为CGFloat值。尝试传递[fontSize floatValue]。
https://stackoverflow.com/questions/7207690
复制相似问题