Domanda

im having this error

    2013-08-20 17:06:57.500 AceXMLSample[13602:11303] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSCache 0x753a5d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key http://skylitecommunication.ipower.com/--irabwha-opc/image/data/1287455832_monotone_fork_spoon_eat_launch_restaurant_dinner.png.'
*** First throw call stack:
(0x1c95012 0x10d2e7e 0x1d1dfb1 0xb7ed1d 0xaeb00b 0xaeafbd 0x2c22 0xd18fb 0xd19cf 0xba1bb 0xcab4b 0x672dd 0x10e66b0 0x2291fc0 0x228633c 0x2291eaf 0x1062bd 0x4eb56 0x4d66f 0x4d589 0x4c7e4 0x4c61e 0x4d3d9 0x502d2 0xfa99c 0x47574 0x4776f 0x47905 0x50917 0x2465 0x14157 0x14747 0x1594b 0x26cb5 0x27beb 0x19698 0x1bf0df9 0x1bf0ad0 0x1c0abf5 0x1c0a962 0x1c3bbb6 0x1c3af44 0x1c3ae1b 0x1517a 0x16ffc 0x219d 0x20c5)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

this is the code where im having this kind of error. dont know what's the prob.

NSString *imageURL = currentData.imageLink;    
NSData *imageData = [myCache valueForKey:imageURL];
if (imageData != nil) {
    [cell.imageShow setImage:[UIImage imageWithData:imageData]];
} else {
    NSData *dataToCache = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]];
    [myCache setObject:dataToCache forKey:imageURL];
    [cell.imageShow setImage:[UIImage imageWithData:dataToCache]];
}
È stato utile?

Soluzione

You haven't given the full error but I guess you need to replace:

NSData *imageData = [myCache valueForKey:imageURL];

with

NSData *imageData = [myCache objectForKey:imageURL];

You might want to add some protection, like:

if (imageURL != nil) {
    NSData *dataToCache = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]];

    if (dataToCache != nil) {
        [myCache setObject:dataToCache forKey:imageURL];
        [cell.imageShow setImage:[UIImage imageWithData:dataToCache]];
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top