なぜ NSOrderedSet 情報が削除されたり、情報が消えたりすることがありますか?
アプリケーションでは、JSON 形式のデータを含む文字列を取得するため、NSOrderedSet を使用して、メソッド「finishedRecomingData」に示すようにキーから受け取った情報に従ってデータを並べ替えますが、その NSOrderedSet を取得してリストに情報を入力すると PickerVied 情報NSOrderedSet に保存されているデータは、ゴミ箱をクリアするか、その他の情報が表示されます。
pickerView "numberOfRowsInComponent" のメソッドを呼び出すときのように、他のメトで NSOrderedSet を呼び出すときに情報が削除される理由を教えてくれる人に感謝します
.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
「finishedRecomingData」の deptoArray のログ
2014-11-30 18:40:33.976 Salud Total[2629:132519] ソロ名: ( "Bogot\U00e1 DC", Antioquia, Atlantico )
"numberOfRowsInComponent" 2014-11-30 18:42:27.279 Salud Total[2629:132519] データの deptoArray のログ: { }
またはメッセージ: Thead 1: EXC_BAD_ACCESS(code=EXC_I386_GPFLT) または 2014-11-30 18:44:34.311 Salud Total[2650:133534] データ: (インデックスなし)