Tuesday, 15 February 2011

ios - Fetching UIImage from Core Data -


I am using core data to save a UIImage that is sent to me in my UIImagePickerController matches (source type = image library). I will then like to place a photo in a place UICollectionViewCell , please help see and check what I'm doing.

This is my UIImagePickerController it is called by a representative.

  - (zero) requestAudscreen {_picker = [[UIImagePickerController alloc] init]; _picker.delegate = self; _picker.allowsEditing = No; _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [Self-present ViewController: _picker animated: yes complete: zero]; } - (Zero) imagePickerController: (UIImagePickerController *) Picker didFinishPickingImage: (UIImage *) Image EditingInfo: (NSDictionary *) editingInfo {AppDelegate * Representative = [UIApplication Sharing Application] .delegate; NSManagedObjectContext * context = [Representative managed object contaxes]; NSEntityDescription * entityDescription = [NSEntityDescription EntityForName: @ Managed Object Contains in "Screen": Reference]; Screen * Nuscrin = [[Screen Alloc] Init With Identity: Insert Entity Details :Managed Contact: Reference]; NSDTa * ImageData = UIImagePNG Mapping (Image); NewScreen.image = imageData; [_product addProjectScreensObject: newScreen]; NSError * error; [Save the reference: & amp; Error]; If (! [Save from context: & amp; Error]) {NSLog (@ "Whoops% @% @", error, [Error localization]]; } [Self shotgun viewer unneeded: _ picture closing: ^ {[_collectionView reloaded data]; }]; }  

And here is my ViewWeel Appear metad. This is where I get data from core data, is this right?

  - (zero) visibleVIPE: animated (BOOL) {[Super Viewer app: zero]; AppDelegate * Representative = [UIApplication shared application]. Delegate; NSManagedObjectContext * context = [Representative managed object contaxes]; // Load Project NSFetchRequest * fetch = [[NSFetchRequest alloc] init]; NSEntityDescription * entity = [NSEntityDescription EntityForName: @ Managed Object Contains in "Project": context]; [SetEntity bring: unit]; NSPredicate * predicate = [NSPredicate predicateWithFormat: @ "name ==% @", @ "EMO-KIT"]; [Set pediatric: present]; NSError * error; NSArray * array = [reference executeFetchRequest: Fetch error: & amp; Error]; If (array.count == 1) {_project = array [0]; } And {_project = [NSEntityDescription insertNewObjectForEntityForName: @ Managed Object Contents in "Project": Reference]; [_project setValue: @for "emo-kit": @ "name"]; } NSArray * screens = [[_project projectcreens] array]; NSIndexPath * bottomIndexPath = [NSIndexPath indexPathForRow: screens.count in attribute: 0]; [Self.collectionView scrollToItemAtIndexPath: Scaloposition on Floor Index: Animated UICollectionViewScrollPositionRight: Yes]; }  

You can convert UIImage to NSData and look in the core data below Can save in

Saving

  NSData * ImageData = UIImagePNG Report (Image); [News oz set value: image data for: @ "image"];  

Recover

  UIImage * image = [UIImage imageWithData: [ScreenObject value FORKEY: @ "image"]];  

Hope this helps you ..


No comments:

Post a Comment