我加載從服務器這是沒有任何問題做工精細的數據,我可以在NSLog
作爲PickerView加載數據的問題
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看到res
值:
@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];
}
評論這// [RES發佈]; –
@Bhumeshwerkatre我會嘗試。 –
首先你再次釋放你的res數組試着去訪問它。所以它會給出例外。消息發送到解除分配的實例。所以不要發佈「res」數組,因爲這將在未來使用。 –