我正在从服务器加载数据工作正常而没有问题我可以在res
中看到NSLog
值为
2013-11-19 16:22:48.799 Paaa[4278:a0b] res ( { "choice_name" = "DATA0"; }, { "choice_name" = "DATA1"; }, { "choice_name" = "DATA2"; } )The problem is I can't view it in the `pickerView` It always indicate to `return [res count]` as EXC_BAD_ACCESS. So please where would be my problem?
·H:
@property (nonatomic, strong) NSMutableArray *res;
.M:
- (void)requestPos:(ASIFormDataRequest *)request{
NSData *responseData = [request responseData];
NSString *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// Create a dictionary from the JSON string
NSDictionary *result = [jsonString JSONValue];
[jsonString release];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithXMLString:[result objectForKey:@"Response"] options:0 error:nil] autorelease];
NSArray *nodes = [doc nodesForXPath:@"/root" error:nil];
NSArray *nodes3 = NULL;
nodes3 = [doc nodesForXPath:@"/root/cl_choicelist/cl_choice" error:nil];
NSLog(@"node3%@", nodes3);
// we will put parsed data in an a array
res = [[NSMutableArray alloc] init];
for (CXMLElement *node in nodes3) {
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
int counter;
for(counter = 0; counter < [node childCount]; counter++) {
// common procedure: dictionary with keys/values from XML node
[item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
}
// and here it is - attributeForName! Simple as that.
[item setObject:[[node attributeForName:@"choice_name"] stringValue] forKey:@"choice_name"]; // <------ this magical arrow is pointing to the area of interest.
[res addObject:item];
[item release];
}
NSLog(@"res %@", res);
[res release];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [res count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [[res objectAtIndex:row]objectForKey:@"choice_name"];
}
- (IBAction)openPickerView{
[actionSheet showInView:self.view];
[UIView beginAnimations:nil context:nil];
[actionSheet setBounds:CGRectMake(0, 0, 320, 492)];
[UIView commitAnimations];
}