我想從我的iPhone應用程序中刪除圖像。 我使用下面的方法,將圖像的名稱作爲參數傳遞。從iPhone中的應用程序目錄中刪除圖像
問題是圖像未被刪除。
- (void)removeImage:(NSString*)fileName {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"%@.png", fileName]];
[fileManager removeItemAtPath: fullPath error:NULL];
NSLog(@"image removed: %@", fullPath);
NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);
}
最後兩行顯示我的應用程序目錄中的內容,我想要刪除的圖像仍然存在。我究竟做錯了什麼?
我試圖刪除我在XCode中添加的圖像,所以它可能在我的包中。這是默認圖像。我試圖刪除這個並添加一個新的。 – bruno 2012-02-23 14:59:13
您無法刪除AppBundle中的圖像(這些圖像是您在Xcode中添加的圖像)。 – rckoenes 2012-02-23 15:04:42
我不能替換默認圖像,而不是刪除它嗎? – bruno 2012-02-23 15:18:00