Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 未发送/接收NSNotificationCenter通知_Objective C_Ios_Nsnotificationcenter - Fatal编程技术网

Objective c 未发送/接收NSNotificationCenter通知

Objective c 未发送/接收NSNotificationCenter通知,objective-c,ios,nsnotificationcenter,Objective C,Ios,Nsnotificationcenter,//问题得到了回答,基本上我应该多睡觉/少编码:) 当我的应用程序启动时,我首先加载启动屏幕,当屏幕本身加载完成时,此启动屏幕将启动数据下载: 飞溅 @implementation Splash - (id) init { self = [super init]; _lblFunds = [[UILabel alloc] initWithFrame:CGRectMake(350, 330, 324,28)]; _lblFunds.numberOfLines = 1;

//问题得到了回答,基本上我应该多睡觉/少编码:)

当我的应用程序启动时,我首先加载启动屏幕,当屏幕本身加载完成时,此启动屏幕将启动数据下载:

飞溅

@implementation Splash


- (id) init
{
    self = [super init];

    _lblFunds = [[UILabel alloc] initWithFrame:CGRectMake(350, 330, 324,28)];
    _lblFunds.numberOfLines = 1;
    [_lblFunds setFont:[UIFont systemFontOfSize:24.0]];
    [_lblFunds setTextAlignment: UITextAlignmentCenter];
    [_lblFunds setText:@".. Fondsen .."];
    [self.view addSubview:_lblFunds];


    _lblObjects = [[UILabel alloc] initWithFrame:CGRectMake(350, 360, 324,28)];
    _lblObjects.numberOfLines = 1;
    [_lblObjects setFont:[UIFont systemFontOfSize:24.0]];
    [_lblObjects setTextAlignment: UITextAlignmentCenter];
    [_lblObjects setText:@".. Vastgoed Objecten .."];
    [self.view addSubview:_lblObjects];


    _lblCustomers = [[UILabel alloc] initWithFrame:CGRectMake(350, 390, 324,28)];
    _lblCustomers.numberOfLines = 1;
    [_lblCustomers setFont:[UIFont systemFontOfSize:24.0]];
    [_lblCustomers setTextAlignment: UITextAlignmentCenter];
    [_lblCustomers setText:@".. Clienten .."];
    [self.view addSubview:_lblCustomers];
    return self;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fundsLoaded) name:@"FundsDone" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(customersLoaded) name:@"CustomersDone" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectsLoaded) name:@"ObjectsDone" object:nil];
}


- (void) fundsLoaded
{
    [_lblFunds setText:[NSString stringWithFormat:@"Fondsen geladen: %d",[[DataManager sharedInstance] fundsCount]]];
}

- (void) objectsLoaded
{
    [_lblObjects setText:[NSString stringWithFormat:@"Vastgoed Objecten geladen: %d",[[DataManager sharedInstance] objectsCount]]];
}

- (void) customersLoaded
{
    [_lblCustomers setText:[NSString stringWithFormat:@"Clienten geladen: %d",[[DataManager sharedInstance] customersCount]]];
}

- (void) viewDidLoad
{
    [super viewDidLoad];
    [[DataManager sharedInstance] getData];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

@end
DataManager随后将继续使用其DataLoader实例在单独的线程中加载和解析数据,每当解析和存储数据时,DataLoader都会发送通知。If以前经常使用通知,但这次它不起作用,我似乎不明白为什么不起作用。没有错误或任何东西,但从未调用在观察器中设置的函数。任何关于什么是错误的想法都是非常受欢迎的,我在这里和其他网站上读了很多帖子,但还没有找到我的答案

DataManager.m

@implementation DataManager

static DataManager* _dataManager = nil;
static DataLoader *_dataLoader = nil;
static bool _dataLoaded = FALSE;

- (int) fundsCount
{
    return _dataLoader.funds_count;
}

- (int) objectsCount
{
    return _dataLoader.objects_count;
}

- (int) customersCount
{
    return _dataLoader.customers_count;
}

+ (DataManager *) sharedInstance{
    @synchronized([DataManager class])
    {
        if(!_dataManager)
        {
            _dataManager = [[super alloc] init];

            _dataLoader = [[DataLoader alloc] init];
        }
        return _dataManager;

    }
    return nil;
}

- (void) loadDataSucces
{
    _dataLoaded = TRUE;
}


- (void) _getData
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    if(_dataLoader)
    {

        [_dataLoader loadData];

    } else
    {
        NSLog(@"DataLoader not initialized");
    }
    [pool drain];
}

- (void) getData
{
    [NSThread detachNewThreadSelector:@selector(_getData) toTarget:self withObject:nil];
}

@end
DataLoader.m

- (void) parseData: (NSString *) jsonString
{

    NSError *err;
    SBJsonParser *parser = [[SBJsonParser alloc] init];
    id object = [parser objectWithString:jsonString error:&err];
    [jsonString release];


    if (!object) {

    } else {

        //funds
        id funds = [object objectForKey:@"fondsen"];


        [self deleteAllEntitiesOfType:@"Fund"];

        int nr = 0;

        for (NSDictionary *i in funds)
        {
            NSString  *naam = [i objectForKey:@"naam"];

            if([naam length] > 2)
            {
                NSManagedObjectContext *context = [(CatalogusAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];


                Fund *f = [NSEntityDescription insertNewObjectForEntityForName:@"Fund" inManagedObjectContext: context];
                NSString *integertje = [i objectForKey:@"oid"];
                int  in = [integertje integerValue];
                [f setOid: [NSNumber numberWithInt: in    ]];
                [f setNaam: naam];
                NSError *error = nil;
                if( ![context save: &error ])
                {
                    NSLog(@"Error: %@", [[error userInfo] valueForKey:@"ErrorString"]);
                } else 
                {
                    nr++;
                }

            }

        }
        funds_count = nr;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"FundsDone" object:nil];
        //objects



        if( true )
        {
            id objects = [object objectForKey:@"vastgoedobjecten"];


            [self deleteAllEntitiesOfType:@"Object"];

            nr = 0;
            NSManagedObjectContext *context = [(CatalogusAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

            for (NSDictionary *i in objects)
            {



                Object *o = [NSEntityDescription insertNewObjectForEntityForName:@"Object" inManagedObjectContext: context];

                [o setFondsOid:[NSNumber numberWithInt: [ [i objectForKey:@"fondsOid"] integerValue]  ]];
                [o setOid: [NSNumber numberWithInt: [ [i objectForKey:@"oid"] integerValue]  ]];
                [o setAdres:[i objectForKey:@"adres"]];
                [o setPostcode:[i objectForKey:@"postcode"]];
                [o setPlaats: [ i objectForKey:@"plaats"]];
                [o setProvincie:[i objectForKey:@"provincie"]];
                [o setStatus:[i objectForKey:@"status"]];
                [o setSegment:[i objectForKey:@"segment"]];
                [o setOppervlakte:[NSNumber numberWithInt: [ [i objectForKey:@"oppervlakte"] integerValue]  ]];
                [o setBelangrijksteHuurder:[i objectForKey:@"belangrijksteHuurder"]];
                [o setWeging:[i objectForKey:@"weging"]];
                [o setLongitude:[NSNumber numberWithDouble: [ [i objectForKey:@"longitude"] doubleValue]  ]];
                [o setLatitude:[NSNumber numberWithDouble: [ [i objectForKey:@"latitude"] doubleValue]  ]];
                NSError *error = nil;
                if( ![context save: &error ])
                {
                    NSLog(@"Error: %@", [[error userInfo] valueForKey:@"ErrorString"]);
                } else 
                {
                    nr++;
                }
            }

            objects_count = nr;
            NSLog(@"ObjectsLoaded");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"ObjectsDone" object:nil];

        }

        //customers
        if( true )
        {
            id custs = [object objectForKey:@"klanten"];


            [self deleteAllEntitiesOfType:@"Customer"];

            nr = 0;
            NSManagedObjectContext *context = [(CatalogusAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

            for (NSDictionary *i in custs)
            {



                Customer *c = [NSEntityDescription insertNewObjectForEntityForName:@"Customer" inManagedObjectContext: context];


                [c setOid: [NSNumber numberWithInt: [ [i objectForKey:@"oid"] integerValue]  ]];
                [c setFondsOid:[NSNumber numberWithInt: [ [i objectForKey:@"fondsOid"] integerValue]  ]];
                [c setNaam: [i objectForKey:@"naam"]];


                NSError *error = nil;
                if( ![context save: &error ])
                {
                    NSLog(@"Error: %@", [[error userInfo] valueForKey:@"ErrorString"]);
                } else 
                {
                    nr++;
                }
            }

            customers_count = nr;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"CustomersDone" object:nil];

        }

    }

    [[NSNotificationCenter defaultCenter] postNotificationName:@"DataReady" object:nil];

}

- (void) loadData{

    NSString *urlString = @"URL";

    NSDate *startDownload = [NSDate date];

    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0];

    NSURLResponse *response = nil;
    NSError *error = nil;



    NSData *dataFeed = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error]; 
    if(error){

        NSString *d = [ error description ];
        NSLog(@"error: %@",d);
    }    int bytes = [dataFeed length];

    NSDate *endDownload = [NSDate date];



    NSString *data = [[NSString alloc] initWithData:[NSData decompress:dataFeed] encoding:NSStringEncodingConversionExternalRepresentation];

    int string = [data length];

    NSDate *endDecompress = [NSDate date];

    NSLog(@"Download data: %f  - Decompress: %f  - BytesDownloaded: %d", [endDownload timeIntervalSinceDate:startDownload], [endDecompress timeIntervalSinceDate:endDownload], bytes);

    [[NSNotificationCenter defaultCenter] postNotificationName:@"DownloadDone" object:nil];

    [self parseData:data];

}

在init中,应该将注册码放在return语句之前。否则它永远不会运行


干杯

在init中,应该将注册码放在return语句之前。否则它永远不会运行


干杯

你只是让我哭泣,微笑,同时感到愚蠢和快乐。谢谢!很高兴我能帮忙!这发生在每个人身上:)干杯。你让我哭泣,微笑,同时感到愚蠢和快乐。谢谢!很高兴我能帮忙!每个人都会这样:)干杯。