2012-04-25 20 views
6

मैं कोर डेटा से संबंधित नौसिखिया हूं। क्या कोई मुझे सही कदम/ट्यूटोरियल प्रदान करने में मदद कर सकता है यह दिखाता है कि छवियों को मूल डेटा और उसके आगमन में कैसे सहेजना है। मैं पहले से स्ट्रिंग डेटा स्टोर करने में सक्षम हूं, लेकिन छवि को सहेजने का प्रयास करते समय मेरा ऐप क्रैश हो जाता है। बचत के लिए:मूल डेटा को छवि सहेजना

DataEvent *event = (DataEvent *)[NSEntityDescription insertNewObjectForEntityForName:@"DataEvent" 
                  inManagedObjectContext:managedObjectContext]; 
NSURL *url2 = [NSURL URLWithString:@"xxxxxxxxxxxxxxx SOME URL xxxxxxxxxxxx"]; 

NSData *data = [[NSData alloc] initWithContentsOfURL:url2]; 
imageSave=[[UIImage alloc]initWithData:data]; 
NSData * imageData = UIImageJPEGRepresentation(imageSave, 100.0);  
[event setValue:self.imageSave forKey:@"pictureData"]; 

retrival के लिए:

DataEvent *event = (DataEvent *)[eventsArray objectAtIndex:indexPath.row]; 
UIImage *image = [UIImage imageWithData:[event valueForKey:@"pictureData"]]; 
UIImageView *imageViewMainBackGround = [[UIImageView alloc] 
CGRect rect3=CGRectMake(0,2,100.0,100.0); 
imageViewMainBackGround.frame = rect3; 
[cell.contentView addSubview:imageViewMainBackGround]; 
[imageViewMainBackGround release]; 
+0

अपने मॉडल फ़ाइल में "pictureData" के लिए एक डेटाप्रकार क्या है:

NSData *imageData = UIImagePNGRepresentation(myUIImage); [newManagedObject setValue:imageData forKey:@"imageKey"]; 

और छवि पुनर्प्राप्त करने के लिए? –

+0

इसकी बाइनरी डेटा प्रकार –

+0

"स्टोर खोलने के लिए उपयोग किया जाने वाला मॉडल स्टोर बनाने के लिए उपयोग किए जाने वाले किसी के साथ असंगत है" आपको यह त्रुटि कहां मिलती है? इस लाइन के बजाय –

उत्तर

0

आप NSData वस्तु के लिए अपने प्रबंधित वस्तु के pictureData मान सेट करने (अपने मामले imageData में) है, नहीं imageSave ऑब्जेक्ट, जो UIImage है।

1

लाइन निम्नलिखित अगर यह आवश्यक नहीं है संकल्प न बदलें ..

NSData * imageData = UIImageJPEGRepresentation(imageSave, 0.0); 

// और बदल

[event setValue:imageData forKey:@"pictureData"]; 

See the store and Retrieve image from core data tutorial with sample code.

आशा, यह आप में मदद मिलेगी ..

+0

ऐसा करने के बाद हाय, मुझे त्रुटि मिल रही है: कारण = "स्टोर को खोलने के लिए इस्तेमाल किया जाने वाला मॉडल स्टोर बनाने के लिए उपयोग किए जाने वाले किसी के साथ असंगत है"; –

+0

जहां बचत या पुनर्प्राप्त .. .. – Nit

+0

छवि डेटा सहेजने में –

2

error: reason = "The model used to open the store is incompatible with the one used to create the store"

समाधान:

सिम्युलेटर से बिल्ड प्रोजेक्ट को हटाएं और उत्पाद टैब से साफ़ करें, अब प्रोजेक्ट चलाएं।

9

सहेजने के लिए:

NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath]; 
UIImage *image = [UIImage imageWithData:[selectedObject valueForKey:@"imageKey"]]; 
[[newCustomer yourImageView] setImage:image]; 

बदली हुई प्रारूप

संबंधित मुद्दे