【问题标题】:Iphone : Problem regarding image Stored in Document Directory?Iphone:有关存储在文档目录中的图像的问题?
【发布时间】:2011-07-13 07:10:23
【问题描述】:

在应用程序中。我正在将服务器中的图像保存在文档目录中。

在数据库中,图像以“image4_12:19:27.png”的形式出现

在文件目录文件夹中,图像存储为“image4_12/19/27.png”

该图像如何在文档目录中将“image4_12:19:27.png”转换为“image4_12/19/27.png”。

我该怎么办?

【问题讨论】:

    标签: iphone objective-c cocoa-touch ios4


    【解决方案1】:

    您可以将文件名拆分为以: 分隔的部分,然后再附加它们。

    NSString * fileName = @"image4_12:19:27.png";
    NSArray * components = [fileName componentsSeparatedByString:@":"];
    
    NSString * relativeFilePath = [components componentsJoinedByString:@"/"];
    NSString * absoluteFilePath = [documentsDirectory stringByAppendingPathComponent:components];
    

    其中documentsDirectory 是文档目录的路径。

    【讨论】:

    • 很好,但是我如何从以下字符串中获取图像名称? "/Users/taxsmart6/Library/Application Support/iPhone Simulator/4.3/Applications/F47B24BB-B480-4154-A2EB-BA6B445B9455/Documents/image1_04:24:28.png";
    • 说这是sourceFilePath。然后fileName = [sourceFilePath lastPathComponent]; 应该给你文件名。
    • componentsSeparatedByString 它返回数组。
    猜你喜欢
    • 2011-08-06
    • 2013-12-02
    • 2014-08-19
    • 2014-09-14
    • 2010-11-04
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多