CGFloat数组帮助-iPhone开发人员 [英] CGFloat array help - iPhone dev
本文介绍了CGFloat数组帮助-iPhone开发人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
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 };
}
}
所以基本上,我想根据不同的图形类型绘制不同的渐变.但是,xCode向我展示了if/else语句中的CGFloat components [8]未使用,并忽略了其值.任何想法是什么问题
So basically, I want to draw different gradients based on different graph types. However, xCode shows me that CGFloat components[8] from if/else statements is unused and ignores its values. Any ideas what is the problem
推荐答案
您要在每个if/else块中声明新的组件数组.您不想这样做,只想将值分配给已经声明的components数组即可.
You are declaring new components arrays in each if/else block. You don't want to do this, you just want to assign the values to the already declared components array.
类似的事情应该起作用:
Something like this should work:
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));
}
}
这篇关于CGFloat数组帮助-iPhone开发人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文