Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复iPhone应用程序中显示空白扇区的饼图错误_Iphone_Xcode - Fatal编程技术网

如何修复iPhone应用程序中显示空白扇区的饼图错误

如何修复iPhone应用程序中显示空白扇区的饼图错误,iphone,xcode,Iphone,Xcode,我正在使用以下代码创建饼图: 馅饼类 @interface PieClass : UIView { NSArray* itemArray; NSArray* myColorArray; int radius; } @property(nonatomic,retain)NSArray* itemArray; @property(nonatomic,retain)NSArray* myColorArray; @property(nonatomic,assign) int radi

我正在使用以下代码创建饼图:

馅饼类

 @interface PieClass : UIView {

NSArray* itemArray;
NSArray* myColorArray; 
int radius;


 }

 @property(nonatomic,retain)NSArray* itemArray;
 @property(nonatomic,retain)NSArray* myColorArray;
 @property(nonatomic,assign) int radius;


@end
Pie类实现

 - (id)initWithFrame:(CGRect)frame
 {
self = [super initWithFrame:frame];
if (self) {
    // Initialization code

}
return self;
}



- (void)drawRect:(CGRect)rect
{


int c=[itemArray count];

CGFloat angleArray[c];
CGFloat offset;
int sum=0;

CGContextRef context = UIGraphicsGetCurrentContext();


CGContextSetAllowsAntialiasing(context, false);
CGContextSetShouldAntialias(context, false);



for(int i=0;i<[itemArray count];i++)

{


    sum+=[[itemArray objectAtIndex:i] intValue];


}


for(int i=0;i<[itemArray count];i++)
{

    angleArray[i]=(float)(([[itemArray objectAtIndex:i] intValue])/(float)sum)*(2*3.14); // in radians
    CGContextMoveToPoint(context, radius, radius);
    if(i==0)
        CGContextAddArc(context, radius, radius, radius, 0,angleArray[i], 0);
    else
        CGContextAddArc(context, radius, radius, radius,offset,offset+angleArray[i], 0);
    offset+=angleArray[i];


    CGContextSetFillColorWithColor(context, ((UIColor *)[myColorArray objectAtIndex:i]).CGColor);
    CGContextClosePath(context); 
    CGContextFillPath(context);

    }
       }

   - (void)dealloc
     {

[super dealloc];

    }

  @end




-(void)createGraph{
    PieClass *myPieClass=[[PieClass alloc]initWithFrame:CGRectMake(25,460,230,200)];
    myPieClass.backgroundColor=[UIColor clearColor];

    int one=[valueOne  intValue];
    int two=[valueTwo intValue];
    int three=[valueThree intValue];
    int four=[valueFour intValue]; 

    int total=one+two+three+four;

    float oneValue=(float)one/(float)total*100;
    float twoValue=(float)two/(float)total*100;
    float threeValue=(float)three/(float)total*100;
    float fourValue=(float)four/(float)total*100;
    float floatTotal=oneValue+twoValue+threeValue+fourValue;

    NSString *value1=[NSString stringWithFormat:@"%f",oneValue];
    NSString *value2=[NSString stringWithFormat:@"%f",twoValue];
    NSString *value3=[NSString stringWithFormat:@"%f",threeValue];
    NSString *value4=[NSString stringWithFormat:@"%f",fourValue];

    myPieClass.itemArray=[[NSArray alloc]initWithObjects:valueOne,valueTwo,valueThree,valueFour, nil];
    myPieClass.myColorArray=[[NSArray alloc]initWithObjects:[UIColor colorWithRed:(128/255.0) green:(100/255.0) blue:(162/255.0) alpha:1],[UIColor colorWithRed:(155/255.0) green:(187/255.0) blue:(89/255.0) alpha:1],[UIColor colorWithRed:(192/255.0) green:(80/255.0) blue:(77/255.0) alpha:1],[UIColor colorWithRed:(79/255.0) green:(129/255.0) blue:(189/255.0) alpha:1], nil];
    myPieClass.radius=100;

    [self.view addSubview:myPieClass];
}
-(id)initWithFrame:(CGRect)frame
{
self=[super initWithFrame:frame];
如果(自我){
//初始化代码
}
回归自我;
}
-(void)drawRect:(CGRect)rect
{
int c=[itemArray count];
CGFloat角度数组[c];
CGFloat偏移量;
整数和=0;
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(上下文,false);
CGContextSetShouldAntialias(上下文,false);

for(int i=0;iPieClass是一个UIView类,它正在创建graph@Radu我已经添加了Pieclass的实现请查看更新的代码图表中缺少紫色饼图。请检查您的输入数据。@我已经检查了输入数据。它在模拟器上运行正常,但在设备上显示缺少的饼图。