How to display all images from NSDocument directory

后端 未结 3 587
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 15:51

First i selected images from photo library to ALAsset Library and after that i stored images in document directory from ALAsset library path.

i am using this code to

3条回答
  •  生来不讨喜
    2020-12-30 16:38

    You can get all the image files from the Document Directory this way:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
    
        NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:nil];
        NSMutableArray *imgFiles = [[NSMutableArray alloc] init];
        for (int i=0; i

    And then you can display the images into the UITableView like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
        img.image = [UIImage imageWithContentsOfFile:[imgFiles objectAtIndex:indexPath.row]];
        [cell addSubview:img];
    
        return cell;
    }
    

    Cheers!!!

提交回复
热议问题