2012-06-21 33 views
0
-(NSString*)dataFilePath{   
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentDirectory = [path objectAtIndex:0]; 

    return [documentDirectory stringByAppendingPathComponent:@"ProperyList.plist"]; 
} 

iDevice無法從此路徑加載數據,只有模擬器可以。iOS plist無法加載數據fim plist,但在模擬器上工作

+2

從** dataFilePath **返回的字符串是什麼** –

+0

如果路徑一切都正確,那麼它可能是文件名區分大小寫的問題。 – Iducool

+0

http://stackoverflow.com/questions/1489522/stringbyappendingpathcomponent-hows-it-work –

回答

1

首先,NSLog你的dataFilePath值從這個方法返回,然後檢查plist文件(PropertyList.plist)是否存在於你的文檔目錄下。使用下面的代碼進行檢查:

NSFileManager *fileManager = [NSFileManager defaultManager]; 
BOOL success = [fileManager fileExistsAtPath:dataFilePath]; 

還必須確認是否是您在使用正確的文件名。 iOS設備區分大小寫,而模擬器不區分大小寫。

+0

我得到了NULL。我猜這意味着該文件不在那裏......那麼,有沒有另一種方法來檢測在Xcode中創建的plists? –

+0

您是否在代碼中以編程方式創建plist,然後將其存儲在文檔目錄中?請檢查您是否使用正確的代碼來執行此操作?您還可以獲得 – AJS

+0

瀏覽或訪問您的系統/用戶/ Lucas/Library/Application Support/iPhone Simulator/5.1/Applications/431BB256-0B69-49DE-A9AE-A78B822572E3/Documents/Proper tyList中的此位置/路徑。 plist並檢查你創建的PropertyList是否存在於這個路徑中。[link](http://stackoverflow.com/questions/8309761/error-writing-to-plist)[link](http://stackoverflow.com/問題/ 7754668 /可 - 不找-的plist文件式的文檔目錄,如何做 - 修改 - 在-plist中,programa) – AJS