2012-11-26 61 views

回答

2

嘗試按照您的應用程序didfinishlaunching方法方法

-(void) checkAndCreateFile 
    { 
     //------------------------------------------- 
     BOOL success; 
     NSFileManager *fileManager = [NSFileManager defaultManager]; 
     success = [fileManager fileExistsAtPath:cFilePath]; 
     //------------------------------------------- 
     //File already there 
     if(success) 
     { 
      return; 
     } 
     //------------------------------------------- 
     //create file 
     NSString *filePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:cfileName]; 
     [fileManager copyItemAtPath:filePathFromApp toPath:cfilePath error:nil]; 

    } 

//------------------------------------------------------------------------ 
// Method : copyFile 
// Method to create file 
//------------------------------------------------------------------------ 
-(void) copyFile 
{ 

     cfileName = @"WinDef.plist"; 

    NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentDir = [documentsPaths objectAtIndex:0]; 
    cfilePath = [documentDir stringByAppendingPathComponent:cfileName]; 
    [self checkAndCreateFile]; 

} 

如果您要訪問,這將如果你想

並保存WinDef.plist文件在您的應用程序文件夾文件值然後您可以通過使用以下代碼檢索它

NSString *path = [[NSBundle mainBundle] pathForResource: @"WinDef" ofType: @"plist"]; 
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile: path]; 
id obj1 = [dictionary objectForKey: @"YourKey"]; 

這會給你在字典中的關鍵價值

+0

哦,我很抱歉。我可能沒有正確解釋我的問題。我希望文件保持在原來的位置。我希望它出現在側邊欄的Project Navigator中。我添加了一個截圖到我的文章。 –

+0

它確定Ronald.Now我已經添加了從你的plist文件根據關鍵值獲取值的代碼。您可以使用此字典來獲得默認設置值 – svrushal

+0

äh,對不起,這就是我已經做的:)你看我是在我的WindowViewHeaderBar工具上做一些測試。在做這件事時,我不時刪除WinDef。現在我正在切換到查找器,手動刪除文件,並在手動刪除文件後將其重新放回到Project Navigator中。我想要的:我想從Project Navigator中刪除該文件,刪除該文件,並希望新創建的文件(已經工作)出現在Project Navigator中。我沒有看到如何將文件導入Project Navigator。 –

相關問題