0

NSMutableDictionary の「辞書」に書き込むときにエラーが発生します。

私のアイテムリストクラスから(以下)を実装する場合:

- (void)setImage:(UIImage *)i forKey:(NSString *)s
{
[dictionary setObject:i forKey:s];
// Create full path for image
NSString *imagePath = [self imagePathForKey:s];

// Turn image into JPEG data,
NSData *d = UIImageJPEGRepresentation(i, 0.5);

// Write it to full path
[d writeToFile:imagePath atomically:YES];
}

DetailViewController:imagePickerController から:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *oldKey = [_detailItem imageKey];

//did the item already have an image
if (oldKey) {
    //delete old image
    [[RoomList sharedStore] deleteImageForKey:oldKey];
}

//get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

//create CFUUID object; it knows how to create uique identifier strings
CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);

//create string from unique identifier
CFStringRef newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);

//use unique ID to set our item's imageKey
NSString *key = (__bridge NSString *)newUniqueIDString;
[_detailItem setImageKey:key];
NSLog(@"image key: %@", key);

[_detailItem setImage:image forKey:key];

//tell objects ointed to by newUniqueIDString and newUniqueID to lose an owner to avoid
//memory leak
CFRelease(newUniqueIDString);
CFRelease(newUniqueID);

//remove image picker (dismiss method)
[self dismissViewControllerAnimated:YES completion:nil];
[self configureView];
}

[_detailItem setImage:image forKey:key]; に関連付けられている次のエラーが発生しています。imagePickerController での操作: -[NSManagedObject setImage:forKey:]: 認識されないセレクターがインスタンス 0x8195770 に送信されました

私の推測では、UIImage *image、NSString *key、またはその両方を objectForKey メソッド "setImage:forKey" に渡すことはできません。これを修正する方法、または回避する方法はありますか?

ありがとう!

4

0 に答える 0