菜鸟教程小白 发表于 2022-12-11 20:19:23

iphone - 如何显示来自 NSDocumentDirectory 的照片


                                            <p><p>我正在 iPad 上开发此应用程序。</p>

<p>“浏览”按钮的这些代码允许用户查看 iPad 画廊中的照片。</p>

<p>代码:</p>

<pre><code>- (IBAction) BrowsePhoto:(id)sender
    {
    UIImagePickerController *imagePickerController = [ init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    UIPopoverController *popover = [ initWithContentViewController:imagePickerController];
    ;
    ;
    self.popoverController = popover;
    ;
    }

When a photo is selected, it will be stored into the application using NSDocumentDirectory.

Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo
    {
    ;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = ;
    NSString *savedImagePath = ;
    UIImage *image = imageView.image;
    NSData *imageData = UIImagePNGRepresentation(image);
    ;
    }
</code></pre>

<p>现在我必须在第一个屏幕上添加一个“显示”按钮。
当点击按钮时,它将显示一个新 View (模态视图 Controller )并显示来自 NSDocumentDirectory 的缩略图/表格 View 中的所有照片。</p>

<p>当一张照片被选中时,它将从 NSDocumentDirectory 中删除。</p>

<p>我该怎么做? </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>要在 iPhone 中删除 NSDocumentDirectory 中的任何文件,你可以使用此代码,</p>

<pre><code>NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES );
NSString *docDirectory = ;
NSString *filePath2 = ;
NSFileManager *fileManager = ;
BOOL exist =;
if(exist)
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 如何显示来自 NSDocumentDirectory 的照片,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7655290/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7655290/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 如何显示来自 NSDocumentDirectory 的照片