开发者

iphone SDK displaying image in uitableview from image data in JSON string

I'm new to this, so here goes..

I'm havi开发者_如何学Gong a problem with displaying images in uitableview, that are downloaded from a mysql database. Here's what I'm doing:

converting images using UIImagePNGRepresentation. uploading to MYSQL database via webservice. So far so good..

The images are downloaded from MYSQL using JSON. NSDictionary used to create array of image data from JSON String. [UIImage imageWithData:[imageArray objectAtIndex:indexpath.row]] fails with error: [NSCFString bytes]: unrecongnised selector sent to instance.

I can understand why this is happening, but don't know how to resolve it. The imageWithData is expecting NSData object, but I've converted the string to NSData with no success.

Any help will be greatly appreciated.


Are you converting to and from data properly?

To data:

NSData* theData;
theData = [theNSString dataUsingEncoding:NSASCIIStringEncoding];

To string:

NSString* theNSString;
theNSString = [[NSString alloc] initWithData:theData encoding:NSASCIIStringEncoding];


Thanks for your response.

Yes I was doing the conversion to/from data, as you stated, the only difference being that I was using NSUTF8StringEncoding rather than NSASCIIStringEncoding.

I've tried it with NSASCIIStringEncoding, but the results is the same. It seems that the converted data is different to that stored on the database.

The data from the JSON string (NSData to NSString) is:

<89504e47 0d0a1a0a 0000000d 49484452 00000087 0000005a 08020000 001d25d2 ac000020 00494441 54780174 bd7778dc e775e73b bdf78e19 f40e1004 c002764a ec942cdb b12ccb55 b6e3123b 8e539e44 cecd3ad7 bbc9c6eb f4dc2789 b3297e9c 4d1cc5b1 2dc9b264 4bb22a25 52ec0401 16f45e07 184ceff3 ....

However, the conversion back to NSData gives the following data:

<3c383935 30346534 37203064 30613161 30612030 30303030 30306420 34393438 34343532 20303030 30303038 37203030 30303030 35612030 38303230 30303020 30303164 32356432 20616330 30303032 30203030 34393434 34312035 34373830.....

This may be the same, but [UIImage imageWithData:theData] returns null image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜