-1

为什么 NSOrderedSet 信息被删除或信息有时会消失?

在应用程序中,我得到一个带有 JSON 格式数据的字符串,因此我使用 NSOrderedSet 根据从键接收到的信息对数据进行排序,如方法“finishedReceivingData”中所示,但是当我使用该 NSOrderedSet 填充列表时 PickerVied 信息存储在 NSOrderedSet 中的清除垃圾或其他信息出现。

谢谢有人能告诉我为什么在其他metos中调用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

“finishedReceivingData”中 deptoArray 的日志

2014-11-30 18:40:33.976 Salud Total[2629:132519] 独奏名称:(“Bogot\U00e1 DC”,安蒂奥基亚,大西洋)

“numberOfRowsInComponent”中 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] 数据:(无索引)

4

1 回答 1

0

感谢您的大力支持,如果没有这个名为“google”的神奇工具,我意识到我错了 NSOrderedSet 引用显然将其用作指向接收到的数据的指针,而不是用作另一个缓冲区。

首先我将 NSOrderedSet 更改为 NSArray 然后

我改变

deptoArray=[NSOrderedSet orderedSetWithArray:[json valueForKey:@"Nombre"]];

为了

deptoArray=[[NSArray alloc]initWithArray:[json valueForKey:@"Nombre"]];

和作品

请不要让我否定我即将阻止我提问而且我是新手,这个论坛是一个很好的帮助工具

于 2014-11-30T23:01:40.427 回答