为什么NSOrderedSet信息被删除或信息有时会消失?
在应用程序中我得到一个包含JSON格式数据的字符串,所以我使用NSOrderedSet根据我从密钥中收到的信息对数据进行排序,如方法" finishedReceivingData"但是当我拿NSOrderedSet填充列表PickerVied时,存储在NSOrderedSet中的信息清除了垃圾或其他信息。
感谢能够告诉我为什么在调用其他元素中的NSOrderedSet时删除信息的原因,例如当我调用pickerView" numberOfRowsInComponent"
的方法时·H
#import <UIKit/UIKit.h>
#import "RestConnectionDelegate.h"
#import "ViewController.h"
@class RestConnection;
@interface attentionCenterViewController : UIViewController<RestConnectionDelegate,UIPickerViewDelegate,UIPickerViewDataSource>{
@private RestConnection *restConnection;
IBOutlet UIPickerView *pvList;
NSDictionary *json;
NSData *encodData;
}
- (IBAction)cbDepto:(id)sender;
- (IBAction)cbCity:(id)sender;
- (IBAction)cbAttent:(id)sender;
- (IBAction)cbFind:(id)sender;
@property (strong, nonatomic) NSOrderedSet *deptoArray;
@end
的.m
#import "attentionCenterViewController.h"
#import "RestConnection.h"
@interface attentionCenterViewController (){
NSString *service;
}
@end
@implementation attentionCenterViewController
#define baseURL @"http://another url"
#pragma mark Setup and Teardown Methods
- (void)viewDidLoad {
[super viewDidLoad];
restConnection = [RestConnection new];
restConnection.baseURLString = baseURL;
restConnection.delegate = self;
viewList.hidden=true;
}
- (void)dealloc {
[restConnection release];
[txtDepto release];
[txtCity release];
[txtAttent release];
[viewList release];
[pvList release];
[super dealloc];
}
#pragma mark RestConnectionDelegate
- (void)finishedReceivingData:(NSData *)data
{
encodData = [[restConnection stringData] dataUsingEncoding:NSUTF8StringEncoding];
json = [NSJSONSerialization JSONObjectWithData:encodData options:0 error:nil];
NSLog(@"Diccionario JSON: %@", json);
if ([service isEqual:@"Depto"]) {
//In this place full array
_deptoArray=[NSOrderedSet orderedSetWithArray:[json valueForKey:@"Nombre"]];
NSLog(@"solo nombre: %@", _deptoArray);
pvList.delegate=self;
viewList.hidden=false;
}
}
- (IBAction)cbDepto:(id)sender {
NSString *urlString = [NSString stringWithFormat:@"ConsultaDepartamentos"];
[restConnection performRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:urlString]]];
service=@"Depto";
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if ([service isEqualToString:@"Depto"]) {
NSLog(@"en el picket: %@", _deptoArray);
NSLog(@"data: %@", encodData);
return [_deptoArray count];
}else{
return 0;
}
}
@end
&#34; finishedReceivingData&#34;
中deptoArray的日志2014-11-30 18:40:33.976 Salud Total [2629:132519] solo nombre :( &#34; Bogot \ U00e1 DC&#34;, 安蒂奥基亚, 大西洋 )
&#34; numberOfRowsInComponent&#34;中的deptoArray的日志 2014-11-30 18:42:27.279 Salud Total [2629:132519]数据:{ }
或 消息:Thead 1:EXC_BAD_ACCESS(code = EXC_I386_GPFLT) 要么 2014-11-30 18:44:34.311 Salud Total [2650:133534]数据:(无索引)
答案 0 :(得分:0)
感谢非常棒的支持,没有这个名为&#34; google&#34;我意识到我错了NSOrderedSet引用显然使用它作为指向接收数据的指针而不是另一个缓冲区。
首先我将NSOrderedSet更改为NSArray然后
我改变了
deptoArray=[NSOrderedSet orderedSetWithArray:[json valueForKey:@"Nombre"]];
的
deptoArray=[[NSArray alloc]initWithArray:[json valueForKey:@"Nombre"]];
并且工作
请不要让我有资格否定我即将阻止我提问,我是新手,这个论坛是一个很好的工具来帮助