How to upload various table images

I have two views in the 1st view that say A to save the image in the document directory when you click the save button and then the second view. B. I have two downloads of this image with a specific table cell. In the code below, I am trying to compare an image with a specific user email id. Email is common in both submissions. So I can distinguish a specific user from my email and in our table view cell we display our images in different ways. But I can’t do it ... How can this be achieved in Ios? AnyOne can help me with this .... My code for saving and uploading images to the document directory enter code here

View A

-(void)saveImage: (UIImage*)image
{
    if (image != nil)
    {
        NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString* path = [documentsDirectory stringByAppendingPathComponent:
                              @"iosImage.png" ];
        NSString *fileName = [path stringByAppendingFormat:email];
        NSLog(@"The result of Concatenate String =%@",fileName);
        NSData* data = UIImagePNGRepresentation(image);
                  [data writeToFile:path atomically:YES];
        NSLog(@"The Path of the directory %@",path);
    }
}

View B

- (UIImage*)loadImage
{
    NSLog(@"Email^^^^^^^^^%@",imgEmail);
    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSArray *paths =        NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString* path = [documentsDirectory stringByAppendingPathComponent:
                          @"iosImage.png" ];
    UIImage* image = [UIImage imageWithContentsOfFile:path];
    NSLog(@"Documents directory: %@",[fileMgr     contentsOfDirectoryAtPath:documentsDirectory error:&error]);
    return image;
}
+4
4

saveImage loadImage, .

-(void)saveImage: (UIImage*)image filePath:(NSString*)fileNameEmail
{
     if (image != nil)
     {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileNameEmail];

        NSData* data = UIImagePNGRepresentation(image);
              [data writeToFile:filePath atomically:YES];

     }
}

- (UIImage*)loadImage:(NSString*)fileNameEmail
{
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileNameEmail];
     UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath];
     return image;
}

. , .

-(UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    cell.youimageview.image = [self loadImage:[[yourArray indexOfObject:indexPath.row] valueForKey:@"youemailkey"]];
    return cell;
}

.

+2

, , , Nil , :

cell.imageView.image = Nil;
+1

Using the code below, we can asynchronously insert the image into the table cell.

NSString *imageName=[NSString stringWithFormat:@"%@.png",d.emailId];

UIImage *image = [self loadImage:imageName];  
if (image==nil)
{
    [imgProfilePic setImage:[UIImage imageNamed:@"userEdit.png"]];
}
else
{
    [imgProfilePic setImage:image];
}
photos =image;

NSLog(@"^^^^^^^^^^^^^^%@",photos);

[cell.contentView addSubview:imgProfilePic];
0
source

You can also use this,

-(NSString *)ImageString{

    NSData *imgdata = UIImageJPEGRepresentation(self.imgView.image, 0.5);
    NSString *imagename =[self generateImageName];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager createFileAtPath:[NSString stringWithFormat:@"%@/%@",   DOCUMENTS_FOLDER,imagename]
                         contents:imgdata
                       attributes:nil];
    return imagename;

    }
       -(NSString *)generateImageName{

        int timestamp = [[NSDate date] timeIntervalSince1970];
        NSString *StrImage = [NSString stringWithFormat:@"Image_%d.png",timestamp];
        NSLog(@"image name=%@",StrImage);
        return StrImage;
    }

And define in the title like this,

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
0
source

All Articles