这是我的代码:
CGFloat components[8];//[8];// = { 0.6, 0.6, 0.6, 0.5, 0.4, 0.4, 0.4, 0.5 };
if ([appDelegate.graphType isEqualToString:@"response"])
{
CGFloat components[8] = { 0.2, 0.2, 0.2, 0.5, 0.5, 0.5, 0.5, 0.5 };
}
else
{
if ([appDelegate.graphType isEqualToString:@"uptime"])
{
CGFloat components[8] = { 0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };
}
else
{
CGFloat components[8] = { 0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };
}
}
Run Code Online (Sandbox Code Playgroud)
所以基本上,我想根据不同的图形类型绘制不同的渐变.但是,xCode向我显示来自if/else语句的CGFloat组件[8]未使用并忽略其值.有什么想法是什么问题
您在每个if/else块中声明新的组件数组.您不希望这样做,您只想将值分配给已声明的组件数组.
这样的事情应该有效:
CGFloat components[8];
const CGFloat components1[8] = { 0.2, 0.2, 0.2, 0.5, 0.5, 0.5, 0.5, 0.5 };
const CGGloat components2[8] = { 0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };
const CGFloat components3[8] = { 0.694, 0.855, 0.961, 0.5, 0.188, 0.588, 0.906, 0.5 };
if ([appDelegate.graphType isEqualToString:@"response"])
{
memcpy(components,components1, 8*sizeof(CGFloat));
}
else
{
if ([appDelegate.graphType isEqualToString:@"uptime"])
{
memcpy(components,components2, 8*sizeof(CGFloat));
}
else
{
memcpy(components,components3, 8*sizeof(CGFloat));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2751 次 |
| 最近记录: |