Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Ios 将PNG保存到磁盘,但将文件路径保存到核心数据_Ios_Objective C_Core Data_Uiimage - Fatal编程技术网

Ios 将PNG保存到磁盘,但将文件路径保存到核心数据

Ios 将PNG保存到磁盘,但将文件路径保存到核心数据,ios,objective-c,core-data,uiimage,Ios,Objective C,Core Data,Uiimage,这里可能有一个重复的问题,但我搜索了一下,没有找到答案 我有一个接受用户签名并将该签名保存为.png文件的应用程序。以下是我使用的代码: -(void)saveSignature { UIGraphicsBeginImageContext(self.frame.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; signature = UIGraphicsGetImageFromCurre

这里可能有一个重复的问题,但我搜索了一下,没有找到答案

我有一个接受用户签名并将该签名保存为.png文件的应用程序。以下是我使用的代码:

-(void)saveSignature

{
    UIGraphicsBeginImageContext(self.frame.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    signature = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData *pngData = UIImagePNGRepresentation(signature);

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"signature.png"];
    [pngData writeToFile:filePath atomically:YES]; //Write the file
}
这段代码非常有效。它将签名的.png保存在我的应用程序的documents文件夹中。我需要做的是将文件路径保存到我的核心数据模型,并通过。核心数据


如果有人能给我指出正确的方向,那就太好了。

你不用说核心数据中是否还有其他内容。如果这样做,只需在模型上创建一个
imagePath
属性,并将文档的路径指定给它。然后,根据模型,在需要时使用UIImage的
imageWithContentsOfFile:
方法将图像加载到UIImage中

如果您还没有准备好核心数据并生成模型,那么,您确实需要学习核心数据,而StackOverflow可能不是最好的地方。也许是个好的开始


当涉及到核心数据时,我的第一条建议是使用库,这使得核心数据的一般使用更加容易。

您不必说核心数据中是否还有其他内容。如果这样做,只需在模型上创建一个
imagePath
属性,并将文档的路径指定给它。然后,根据模型,在需要时使用UIImage的
imageWithContentsOfFile:
方法将图像加载到UIImage中

如果您还没有准备好核心数据并生成模型,那么,您确实需要学习核心数据,而StackOverflow可能不是最好的地方。也许是个好的开始


关于核心数据,我的第一条建议是使用库,这使核心数据的一般使用变得更加容易。

问题出在哪里?您所需要做的就是将filePath分配给托管对象的string属性并保存上下文?如果我调用它,核心数据不会返回字符串吗?似乎有什么问题?您所需要做的就是将filePath分配给托管对象的string属性并保存上下文?如果我调用它,核心数据不会返回字符串吗?谢谢。我已经设置了核心数据,我有一个实体和三个属性。我想为图像添加第四个。我假设将imagePath添加为字符串。谢谢你的帮助!谢谢我已经设置了核心数据,我有一个实体和三个属性。我想为图像添加第四个。我假设将imagePath添加为字符串。谢谢你的帮助!