Xcode CGRect неверный контекст - PullRequest
0 голосов
/ 20 января 2020

Работало приложение, которое использовало устаревшие вызовы NSURL для получения XML данных с сервера; разобрать; рисовать гистограммы. Теперь установка новых утвержденных NSURL вызовов (и работает для создания меток).

     NSCharacterSet *set = [NSCharacterSet URLQueryAllowedCharacterSet];
     NSString *encodedUrlAsString = [urlAsString stringByAddingPercentEncodingWithAllowedCharacters:set];

     NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

     [[session dataTaskWithURL:[NSURL URLWithString:encodedUrlAsString]
             completionHandler:^(NSData *myData, NSURLResponse *response, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{


    NSString *str = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];


    do {

        //Parse XML here - works - NSLog outputs valid data which does create labels

        float startx = 20.0;
        float endx = 20.0 + (40.0 * (wins / 100.0));
        starty = starty + 48.0;
        endy = endy + 48.0;


        //Draw Lines - 1 green, 1 red...
        //             - green (val1) 
        //             - red (val2) 

        CGContextRef context = UIGraphicsGetCurrentContext();
        UIColor * redColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
        UIColor * greenColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];

        CGContextSetLineWidth (context, 24.0);

        // Val1

        CGContextSetStrokeColorWithColor (context, greenColor.CGColor);

        CGContextMoveToPoint(context, startx, starty);
        CGContextAddLineToPoint(context, endx, endy);
        float endxold = endx;
        float endyold = endy;


        CGContextStrokePath (context);

        // Val2

        starty = starty + 28;
        endy = endy + 28;
        endx = 20.0 + (40.0 * (losses / 100.0));

        CGContextSetStrokeColorWithColor (context, redColor.CGColor);
        CGContextMoveToPoint(context, startx, starty);
        CGContextAddLineToPoint(context, endx, endy);
        CGContextStrokePath (context);

        // Text
        UILabel *yrLabel = [[UILabel alloc] init];
        yrLabel.text = description3;
        float yry = endy - 56.0;
        yrLabel.frame = CGRectMake(startx,yry, 64, 16);
        [yrLabel setFont:[UIFont fontWithName:@"Helvetica" size:12]];
        [self addSubview:yrLabel];
        UILabel *newLabelW = [[UILabel alloc] init];
        yry = yry + 12.0;


        Labels created here


    } while ((specificItem = specificItem->nextSibling) != nil);

закрытие циклов, конец.

Приложение работает, ярлыки создаются, но нет линий. Ошибка журнала выводит несколько (по одному для каждого ссылки на контекст) "[Неизвестное имя процесса] CGContextDrawPath: недопустимый контекст 0x0". Попытка перемещения вызова CGContextRef для создания контекста из диспетчеризации l oop - без ошибок, но снова без линий.

...