Ios can';t在饼图推车中添加动态值 // //PieChartTest.m //宫崎骏 // //苹果于2016年3月25日创建。 //版权所有(c)2016苹果公司。版权所有。 // #导入“PieChartTest.h” #导入“testingvc.h” @接口测试() @属性(强,非原子)NSMutableArray*值; @属性(强,非原子)NSMutableArray*TestArray; @属性(强,非原子)NSMutableArray*标签; @属性(强,非原子)NSMutableArray*颜色; @性质(非原子)布尔插入; @属性(强,非原子)NSArray*颜色1; @属性(强,非原子)NSDictionary*serviceResponse; @属性(强,非原子)NSString*项; @属性(强,非原子)NSArray*temp; @属性(强,非原子)NSDictionary*样本; @结束 @实施测试 @综合目标; @合成str1; @合成str2; -(无效)viewDidLoad{ [超级视图下载]; NSString*baseURL=[NSString stringWithFormat:@”http://192.168.1.122:8099/YazakiService.svc/SESSION/%@/%@/%@“,dictObject,str1,str2]; NSURL*url=[NSURL URLWithString:[baseURL StringByAddingPercents EscapeSusingEncoding:NSUTF8StringEncoding]; NSURLRequest*request=[nsurlRequestRequestWithURL:url]; NSURLResponse*响应; n错误*错误; NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&响应错误:&错误]; _serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableContainers错误:&错误]; NSArray*temp=[\u serviceResponse objectForKey:@“SESSIONCOUNT”]; NSDictionary*sample=[temp objectAtIndex:0]; NSString*项=[sample objectForKey:@“COUNTVALUE”]; 如果([\u serviceResponse objectForKey:@“SESSIONCOUNT”]==nil|| [[U serviceResponse objectForKey:@“SESSIONCOUNT”]isEqual:[NSNull null]]{ //无所事事 }否则 { NSArray*temp=[\u serviceResponse objectForKey:@“SESSIONCOUNT”]; if([temp iskindof类:[NSArray类]]&&temp.count!=0) { //价值是可用的 [self.values removeAllObjects]; self.values=[NSMutableArray new]; int i; 对于(i=0;i

Ios can';t在饼图推车中添加动态值 // //PieChartTest.m //宫崎骏 // //苹果于2016年3月25日创建。 //版权所有(c)2016苹果公司。版权所有。 // #导入“PieChartTest.h” #导入“testingvc.h” @接口测试() @属性(强,非原子)NSMutableArray*值; @属性(强,非原子)NSMutableArray*TestArray; @属性(强,非原子)NSMutableArray*标签; @属性(强,非原子)NSMutableArray*颜色; @性质(非原子)布尔插入; @属性(强,非原子)NSArray*颜色1; @属性(强,非原子)NSDictionary*serviceResponse; @属性(强,非原子)NSString*项; @属性(强,非原子)NSArray*temp; @属性(强,非原子)NSDictionary*样本; @结束 @实施测试 @综合目标; @合成str1; @合成str2; -(无效)viewDidLoad{ [超级视图下载]; NSString*baseURL=[NSString stringWithFormat:@”http://192.168.1.122:8099/YazakiService.svc/SESSION/%@/%@/%@“,dictObject,str1,str2]; NSURL*url=[NSURL URLWithString:[baseURL StringByAddingPercents EscapeSusingEncoding:NSUTF8StringEncoding]; NSURLRequest*request=[nsurlRequestRequestWithURL:url]; NSURLResponse*响应; n错误*错误; NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&响应错误:&错误]; _serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableContainers错误:&错误]; NSArray*temp=[\u serviceResponse objectForKey:@“SESSIONCOUNT”]; NSDictionary*sample=[temp objectAtIndex:0]; NSString*项=[sample objectForKey:@“COUNTVALUE”]; 如果([\u serviceResponse objectForKey:@“SESSIONCOUNT”]==nil|| [[U serviceResponse objectForKey:@“SESSIONCOUNT”]isEqual:[NSNull null]]{ //无所事事 }否则 { NSArray*temp=[\u serviceResponse objectForKey:@“SESSIONCOUNT”]; if([temp iskindof类:[NSArray类]]&&temp.count!=0) { //价值是可用的 [self.values removeAllObjects]; self.values=[NSMutableArray new]; int i; 对于(i=0;i,ios,objective-c,Ios,Objective C,您应尝试更改此行: // // PieChartTest.m // Yazaki // // Created by apple on 3/25/16. // Copyright (c) 2016 apple. All rights reserved. // #import "PieChartTest.h" #import "testingvc.h" @interface PieChartTest () @property (strong, nonatomic) NSMutableAr

您应尝试更改此行:

//
//  PieChartTest.m
//  Yazaki
//
//  Created by apple on 3/25/16.
//  Copyright (c) 2016 apple. All rights reserved.
//

#import "PieChartTest.h"

#import "testingvc.h"
@interface PieChartTest ()
@property (strong, nonatomic) NSMutableArray *values;
@property (strong, nonatomic) NSMutableArray *testARYY;
@property (strong, nonatomic) NSMutableArray *labels;
@property (strong, nonatomic) NSMutableArray *colors;
@property (nonatomic) BOOL inserting;
@property (strong, nonatomic) NSArray *colors1;
@property (strong, nonatomic) NSDictionary *serviceResponse;
@property(strong,nonatomic) NSString *item;
@property(strong,nonatomic)  NSArray *temp;
@property (strong, nonatomic) NSDictionary *sample;
@end

@implementation PieChartTest
@synthesize dictObject;
@synthesize str1;
@synthesize str2;
- (void)viewDidLoad {
    [super viewDidLoad];


    NSString *baseURL = [NSString stringWithFormat:@"http://192.168.1.122:8099/YazakiService.svc/SESSION/%@/%@/%@",dictObject,str1,str2];


    NSURL *url = [NSURL URLWithString:[baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];


    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    NSURLResponse *response;


    NSError *error;


    NSData *responseData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

  _serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];

    NSArray *temp =   [_serviceResponse objectForKey:@"SESSIONCOUNT"];
    NSDictionary *sample=[temp objectAtIndex:0];
   NSString*item=[sample objectForKey:@"COUNTVALUE"];


    if( [_serviceResponse objectForKey:@"SESSIONCOUNT"] == nil ||
       [[_serviceResponse objectForKey:@"SESSIONCOUNT"] isEqual:[NSNull null]] ){
        // do nothing
    }else
    {
        NSArray *temp =   [_serviceResponse objectForKey:@"SESSIONCOUNT"];
        if ([temp isKindOfClass:[NSArray class]] && temp.count !=0)

        {
            // value is available
            [self.values removeAllObjects];
            self.values = [NSMutableArray new];
            int i;

            for (i=0; i<[temp count]; i++) {
                [self.values addObject:[NSString stringWithFormat:@"%@",[[temp objectAtIndex:i] objectForKey:@"COUNTVALUE"]]];
                [self.values addObject:[NSString stringWithFormat:@"%@",[[temp objectAtIndex:i] objectForKey:@"SESSIONVALUE"]]];
            }

        }
    }


   self.pieChartView.dataSource = self;
    self.pieChartView.delegate = self;
    self.pieChartView.animationDuration = 0.5;
    self.pieChartView.sliceColor = [MCUtil flatWetAsphaltColor];
    self.pieChartView.borderColor = [MCUtil flatSunFlowerColor];
    self.pieChartView.selectedSliceColor = [MCUtil flatSunFlowerColor];
    self.pieChartView.textColor = [MCUtil flatSunFlowerColor];
    self.pieChartView.selectedTextColor = [MCUtil flatWetAsphaltColor];
    self.pieChartView.borderPercentage = 0.01;


}

- (NSInteger)numberOfSlicesInPieChartView:(MCPieChartView *)pieChartView {


    return self.values.count;
}
- (CGFloat)pieChartView:(MCPieChartView *)pieChartView valueForSliceAtIndex:(NSInteger)index {


   return [[self.values objectAtIndex:index] floatValue];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)pieChartView:(MCPieChartView*)pieChartView didSelectSliceAtIndex:(NSInteger)index;
{

     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

   testingvc *destViewController =  (testingvc*)[storyboard instantiateViewControllerWithIdentifier:@"testing"];
    self.values =   [_serviceResponse objectForKey:@"SESSIONCOUNT"];
    // //destViewController = [CategoryVC.destViewController objectAtIndex:0];
    NSDictionary *sample=[self.values objectAtIndex:index];
     NSString*item=[sample objectForKey:@"SESSIONVALUE"];
    //
    destViewController.category = item;
    destViewController.STATUS =dictObject;
    destViewController.fromDate=str1;
      destViewController.Todate=str2;
    [destViewController setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:destViewController animated:NO completion:nil];
}


@end
对此

return [[self.values objectAtIndex:index] floatValue];

错误表示您正试图调用
NSMutableDictionary
上的
floatValue
函数,据我所知,您应该调用字典“COUNTVALUE”键下存储的值。

您应该尝试更改此行:

//
//  PieChartTest.m
//  Yazaki
//
//  Created by apple on 3/25/16.
//  Copyright (c) 2016 apple. All rights reserved.
//

#import "PieChartTest.h"

#import "testingvc.h"
@interface PieChartTest ()
@property (strong, nonatomic) NSMutableArray *values;
@property (strong, nonatomic) NSMutableArray *testARYY;
@property (strong, nonatomic) NSMutableArray *labels;
@property (strong, nonatomic) NSMutableArray *colors;
@property (nonatomic) BOOL inserting;
@property (strong, nonatomic) NSArray *colors1;
@property (strong, nonatomic) NSDictionary *serviceResponse;
@property(strong,nonatomic) NSString *item;
@property(strong,nonatomic)  NSArray *temp;
@property (strong, nonatomic) NSDictionary *sample;
@end

@implementation PieChartTest
@synthesize dictObject;
@synthesize str1;
@synthesize str2;
- (void)viewDidLoad {
    [super viewDidLoad];


    NSString *baseURL = [NSString stringWithFormat:@"http://192.168.1.122:8099/YazakiService.svc/SESSION/%@/%@/%@",dictObject,str1,str2];


    NSURL *url = [NSURL URLWithString:[baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];


    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    NSURLResponse *response;


    NSError *error;


    NSData *responseData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

  _serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];

    NSArray *temp =   [_serviceResponse objectForKey:@"SESSIONCOUNT"];
    NSDictionary *sample=[temp objectAtIndex:0];
   NSString*item=[sample objectForKey:@"COUNTVALUE"];


    if( [_serviceResponse objectForKey:@"SESSIONCOUNT"] == nil ||
       [[_serviceResponse objectForKey:@"SESSIONCOUNT"] isEqual:[NSNull null]] ){
        // do nothing
    }else
    {
        NSArray *temp =   [_serviceResponse objectForKey:@"SESSIONCOUNT"];
        if ([temp isKindOfClass:[NSArray class]] && temp.count !=0)

        {
            // value is available
            [self.values removeAllObjects];
            self.values = [NSMutableArray new];
            int i;

            for (i=0; i<[temp count]; i++) {
                [self.values addObject:[NSString stringWithFormat:@"%@",[[temp objectAtIndex:i] objectForKey:@"COUNTVALUE"]]];
                [self.values addObject:[NSString stringWithFormat:@"%@",[[temp objectAtIndex:i] objectForKey:@"SESSIONVALUE"]]];
            }

        }
    }


   self.pieChartView.dataSource = self;
    self.pieChartView.delegate = self;
    self.pieChartView.animationDuration = 0.5;
    self.pieChartView.sliceColor = [MCUtil flatWetAsphaltColor];
    self.pieChartView.borderColor = [MCUtil flatSunFlowerColor];
    self.pieChartView.selectedSliceColor = [MCUtil flatSunFlowerColor];
    self.pieChartView.textColor = [MCUtil flatSunFlowerColor];
    self.pieChartView.selectedTextColor = [MCUtil flatWetAsphaltColor];
    self.pieChartView.borderPercentage = 0.01;


}

- (NSInteger)numberOfSlicesInPieChartView:(MCPieChartView *)pieChartView {


    return self.values.count;
}
- (CGFloat)pieChartView:(MCPieChartView *)pieChartView valueForSliceAtIndex:(NSInteger)index {


   return [[self.values objectAtIndex:index] floatValue];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)pieChartView:(MCPieChartView*)pieChartView didSelectSliceAtIndex:(NSInteger)index;
{

     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

   testingvc *destViewController =  (testingvc*)[storyboard instantiateViewControllerWithIdentifier:@"testing"];
    self.values =   [_serviceResponse objectForKey:@"SESSIONCOUNT"];
    // //destViewController = [CategoryVC.destViewController objectAtIndex:0];
    NSDictionary *sample=[self.values objectAtIndex:index];
     NSString*item=[sample objectForKey:@"SESSIONVALUE"];
    //
    destViewController.category = item;
    destViewController.STATUS =dictObject;
    destViewController.fromDate=str1;
      destViewController.Todate=str2;
    [destViewController setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:destViewController animated:NO completion:nil];
}


@end
对此

return [[self.values objectAtIndex:index] floatValue];
错误表示您正试图调用
NSMutableDictionary
上的
floatValue
函数,据我所知,您应该调用字典“COUNTVALUE”键下存储的值。

更改此设置

return [[self.values objectAtIndex:index][@"COUNTVALUE"] floatValue];
self.values=[\u serviceResponse objectForKey:@“SESSIONCOUNT”];
NSLog(@“got response=%@”,self.values);
int i;
对于(i=0;i0)
{ 
[self.values removeAllObjects];
self.values=[NSMutableArray new];
对于(i=0;i

return [[self.values objectAtIndex:index][@"COUNTVALUE"] floatValue];
self.values=[\u serviceResponse objectForKey:@“SESSIONCOUNT”];
NSLog(@“got response=%@”,self.values);
int i;
对于(i=0;i0)
{ 
[self.values removeAllObjects];
self.values=[NSMutableArray new];

对于(i=0;不起作用)我们可以逐步了解现在***由于未捕获异常“NSRangeException”终止应用程序时遇到的错误,原因:'***-[\uu NSArrayM objectAtIndex:]:索引0超出边界我点空数组太多了我得到了answer@fathima--欢迎…不,这不起作用,请逐步了解我们现在遇到的错误***由于未捕获的异常“NSRangeException”终止应用程序,原因:'***-[\uu NSArrayM objectAtIndex:]:索引0超出边界我点空数组太多了我得到了answer@fathima--欢迎。。。
if( [_serviceResponse objectForKey:@"SESSIONCOUNT"] == nil ||  
[[_serviceResponse objectForKey:@"SESSIONCOUNT"] isEqual:[NSNull null]] ){
 // do nothing
  }else
  {
 NSArray *temp =   [_serviceResponse objectForKey:@"SESSIONCOUNT"];
  if ([temp isKindOfClass:[NSArray class]] && temp.count !=0)

  {
 // value is available
  [self.values removeAllObjects];
 self.values = [NSMutableArray new];


for (i=0; i<[temp count]; i++) {
    [self.values addObject:[NSString Stringwithformat:@"%@",[[temp objectAtIndex:i] objectForKey:@"COUNTVALUE"]]];
      }

  }
}