Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在iPod Touch上写入属性列表不起作用,但在模拟器中起作用_Iphone_Objective C_Cocoa Touch_Ipod Touch - Fatal编程技术网

Iphone 在iPod Touch上写入属性列表不起作用,但在模拟器中起作用

Iphone 在iPod Touch上写入属性列表不起作用,但在模拟器中起作用,iphone,objective-c,cocoa-touch,ipod-touch,Iphone,Objective C,Cocoa Touch,Ipod Touch,在我正在编写的应用程序中,我试图将一个幸运饼的财富列表写入一个属性列表。在模拟器中,这是预期的工作,一切都很好。在iPodtouch上,我看到的是上面所说的列表,很好,但它从不更新列表 使用模拟器更新属性列表和使用iPod Touch更新属性列表有什么区别吗 if(indexEdit == [data count]) { NSString *temp = [NSString stringWithFormat:@"%@", textField.text];

在我正在编写的应用程序中,我试图将一个幸运饼的财富列表写入一个属性列表。在模拟器中,这是预期的工作,一切都很好。在iPodtouch上,我看到的是上面所说的列表,很好,但它从不更新列表

使用模拟器更新属性列表和使用iPod Touch更新属性列表有什么区别吗

    if(indexEdit == [data count])
    {
        NSString *temp = [NSString stringWithFormat:@"%@", textField.text];
        [self.data addObject:temp];
    }
    else
    {
        NSString *temp = [NSString stringWithFormat:@"%@", textField.text];
        [data replaceObjectAtIndex:indexEdit withObject:temp];
    }
    NSString *errorDesc;
    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Fortunes"  ofType:@"plist"];
    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:data format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
    if (plistData)
    {
        [plistData writeToFile:bundlePath atomically:YES];
    }
    else 
    {
        NSLog(errorDesc);
        [errorDesc release];
    }

我认为您的应用程序包被认为几乎是只读的。如果要编写文件,应将其放入“Documents”文件夹中,如:

NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSMutableString *savePath = [NSMutableString stringWithString:[savePaths objectAtIndex:0]];
[savePath appendString:@"/Fortunes"];

// blah blah

[plistData writeToFile:savePath atomically:YES];

我认为您的应用程序包被认为几乎是只读的。如果要编写文件,应将其放入“Documents”文件夹中,如:

NSArray *savePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSMutableString *savePath = [NSMutableString stringWithString:[savePaths objectAtIndex:0]];
[savePath appendString:@"/Fortunes"];

// blah blah

[plistData writeToFile:savePath atomically:YES];

我不得不说是财富,而不是财富,但它起作用了。谢谢。我会这样做:NSString*filename=[savePathstringByAppendingPathComponent:@“Fortunes.plist”];相反,这样你就不用担心了,好的,本尼。为我辩护,我第一次开始学习Cocoa时就写了这段代码!我不得不说是财富,而不是财富,但它起作用了。谢谢。我会这样做:NSString*filename=[savePathstringByAppendingPathComponent:@“Fortunes.plist”];相反,这样你就不用担心了,好的,本尼。为我辩护,我第一次开始学习Cocoa时就写了这段代码!