我是新来的iOS我很努力地在使用nsurlconnection POST方法的选取器视图中显示值(id)的特定对象。当我单击按钮时使用nslog显示“id”的所有值,但不在选择器视图中。nsurlconnection在iOS中的选择器视图
编码
按钮动作:
-(IBAction)sendDataUsingGet:(id)sender{
[self sendDataToServer : @"GET"];
[self.pickerdata reloadAllComponents];
[self.view addSubview:pickerdata];
}
委托方法:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSMutableString *responseStringWithEncoded = [[NSMutableString alloc] initWithData: mutableData encoding:NSUTF8StringEncoding];
//NSLog(@"%@",responseStringWithEncoded );// this nslog will display all d response....
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData: mutableData
options:kNilOptions
error:&error]; //Now we got top level dictionary
arry = [json valueForKeyPath:@"BranchByList.id"];
NSLog(@"%@",arry);
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[responseStringWithEncoded dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
serverResponse.attributedText = attrStr;
}
选择器视图:
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;{
return [arry count];
//[self.pickerdata reloadAllComponents];
}
-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;{
return [[arry objectAtIndex:row] valueForKey:@"currency"];
//[self.pickerdata reloadAllComponents];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
{
NSLog([arry objectAtIndex:row]);
}
你不应该在新项目中使用NSURLConnection的分配新的数据,它的弃用。 – HAS