简体   繁体   中英

'NSInvalidArgumentException', reason: '-[__NSCFConstantString addObject:]: unrecognized selector sent to instance

-(void)downloadResult:(id)data
{
   if([data isKindOfClass:[NSArray class]])
   {
       if ([data count]==3) 
       {
           if ([dataResultDictionary count]) 
           {
                [[dataResultDictionary objectForKey:[data objectAtIndex:0]] addObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]];
           }
           else
           {
               [dataResultDictionary setObject:[NSMutableArray arrayWithObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]] forKey:[data objectAtIndex:0]];
           }
           if([dataResultDictionary count])
           {
                if ([[dataResultDictionary objectForKey:[data objectAtIndex:0]] count] == requiredResultCount) 
                 {
                    [downloadControlQueue cancelAllOperations];
                    [downloadControlQueue release];
                    downloadControlQueue = nil;
                    processing = YES;
                    [self procesResultData];
                }
            }

      }
      else
      {
            BOOL errorResult = TRUE;

            if ([data count]) 
            {
                        if ([[data lastObject] isKindOfClass:[NSMutableDictionary class]]) {
                            if ([[data lastObject] count]) {
                                if ([[[[data lastObject] allValues] objectAtIndex:0] count]) {

                                    [dataResultDictionary setObject:[data lastObject] forKey:[data objectAtIndex:0]];
                                    errorResult = false;
                }

               }
          }
       }

            if(errorResult)
            {
                [dataResultDictionary setObject:@"" forKey:[data objectAtIndex:0]];
            }
            if ([dataResultDictionary count] == requiredResultCount) {
                [downloadControlQueue cancelAllOperations];
                [downloadControlQueue release];
                downloadControlQueue = nil;
                processing = YES;
                [self procesResultData];

            }
            }
        }


    }

I AM GETTING DATA FROM SERVER. I WANT SHOW DOWNLOAD RESULT IN % VALUE IN IMAGE. BUT I AM GETTING CRASH . INITIALLY THIS METHOD IS WOTKING. I AM SHOWING DATA UPTO 70% IN IMAGE BUT REST OF PART IS CRASHED .HELP ME

Answer to your query, as suggested by rakeshNS, it seems that [dataResultDictionary objectForKey:[data objectAtIndex:0]] is not a NSMutableArray . Instead it is a NSString .

Why are you trying to addObject: in parsed array, which ,btw, is non-mutable ( NSArray )? You should really rethink the parsing logic. If required create a separate model class to store the parsed data. You can create the mutable array and store values in this model class.

In your case [dataResultDictionary objectForKey:[data objectAtIndex:0]] is not an array it is NSString. So you are getting exception. try

if ([dataResultDictionary count]) {
     if([[dataResultDictionary objectForKey:[data objectAtIndex:0]] isKindOfClass:[NSArray class]]){
          [[dataResultDictionary objectForKey:[data objectAtIndex:0]] addObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]];
     }
}
else
{
     [dataResultDictionary setObject:[NSMutableArray arrayWithObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]] forKey:[data objectAtIndex:0]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM