在iOS 9中快照未渲染的视图会导致空快照?

时间:2016-04-27 05:57:34

标签: ios objective-c uitableview uiimagepickercontroller

我有一个tableview控制器,我有很多自定义单元格。每个自定义单元格我都有一个相机图标。当我按下相机时,我会显示一个相机。我的代码工作正常。但是当数量图片在最终应用程序崩溃时增加。我正在使用下面的代码。

-(void)takePhoto : (UITapGestureRecognizer *)sender
{

    NSInteger val = sender.view.tag;
    NSLog(@"val is %lu",(long)val);
    self.componentImage = [self.componentsData objectAtIndex:val];
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;

        [self presentViewController:picker animated:YES completion:^{ }];
    }
    else
    {
        [self showAlert:@"Unable to find camera on your device" Title:@"Camera Unavailable"];
    }

}

拍摄照片后调用的代表。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *originalImage = info[UIImagePickerControllerOriginalImage];
    originalImage = [self resizeImage:originalImage];
    imageData = UIImagePNGRepresentation(originalImage);
    NSData *ada=UIImageJPEGRepresentation(originalImage, 1.0);
    long dateInSeconds =  [[NSDate date] timeIntervalSince1970];
    NSString *unfilteredString = self.componentImage.componentName;
    NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:FILTERED_CHARACTER_SET] invertedSet];
    NSString *resultString = [[unfilteredString componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];
    NSString *component_image_name = [resultString stringByReplacingOccurrencesOfString:@" " withString:@"_"];
    NSString *imageTitle = [component_image_name stringByAppendingString:@"_"];
    imageTitle = [imageTitle stringByAppendingString:self.componentImage.componentid];
    imageTitle = [imageTitle stringByAppendingString:@"_"];
    imageTitle = [imageTitle stringByAppendingString:[NSString stringWithFormat:@"%lu",dateInSeconds]];
    imageTitle = [imageTitle stringByAppendingString:@".jpg"];
    [self.allImageArray addObject:imageTitle];
    NSLog(@"image name clicked %@",self.componentImage.imageName);
    if(self.componentImage.imageName == NULL)
    {
        self.componentImage.componentAllImages = imageTitle;
        self.componentImage.imageName =[[NSMutableArray alloc]init];
        [self.componentImage.imageName addObject:imageTitle];
        self.componentImage.imageClickedTime = [[NSMutableArray alloc]init];
        NSString *image_clicked_time = [self getClickTime];
        [self.componentImage.imageClickedTime addObject:image_clicked_time];
        self.componentImage.componentAllImagesTime = image_clicked_time;
    }
    else
    {
        self.componentImage.componentAllImages = [self.componentImage.componentAllImages stringByAppendingString:@", " ];
        self.componentImage.componentAllImages = [self.componentImage.componentAllImages stringByAppendingString:imageTitle];
        [self.componentImage.imageName addObject:imageTitle];
        NSString *image_clicked_time = [self getClickTime];
        [self.componentImage.imageClickedTime addObject:image_clicked_time];
        self.componentImage.componentAllImagesTime = [self.componentImage.componentAllImagesTime stringByAppendingString:@", "];
        self.componentImage.componentAllImagesTime = [self.componentImage.componentAllImagesTime stringByAppendingString:image_clicked_time];
    }
    NSInteger index = [self.componentsData indexOfObject:self.componentImage];
    NSString *imagesCount = [NSString stringWithFormat:@"%d",(int)[self.componentImage.imageName count]];
    if([imagesCount intValue] != 0)
    {
        InspectionComponentCell *cell = [self.inspTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
        UIImageView *imgView = cell.camera_img;
        imgView.image = [UIImage imageNamed:@"camera-with-glow.png"];
        UIImageView *countImage = cell.count_circle_img;
        countImage.hidden = NO;
        UILabel *label = cell.count_circle_lbl;
        label.hidden = NO;
        label.text = imagesCount;
    }

    [picker dismissViewControllerAnimated:YES completion:^{ }];
    [[DBManager getSharedInstance]insertComponentDetailsData:self.componentImage :[userValidData objectAtIndex:0] ];
    if(self.componentImage.componentWorkorderid != nil)
    {
        [[DBManager getSharedInstance]updateNewWorkOrderData:self.componentImage];
    }
    [self saveImageLocallyImmediately : imageTitle : imageData];
}

0 个答案:

没有答案