|
|
#26 |
|
Also, you need to set up all of the instance variables in ImageLoader in the
loadImageFromURL:withCallbackTarget:withCallbackSelector: method, because imageURL, callbackTarget, and callbackSelector are all undefined when sendImageBack: is being called |
|
|
|
0
|
|
|
#27 |
|
I made all the modifications you suggested. but i receive an error. "terminating due to uncaught exception"
in my custom table cell class i have this function which sets the custom data to the cell: Code:
-(void) setData:(NSDictionary *) dict
{
self.titleLabel.text = [ dict objectForKey:@"title" ];
self.dateLabel.text = [ dict objectForKey:@"pubDate" ];
self.URL = [ dict objectForKey:@"link" ];
NSMutableString *temp = [[NSMutableString alloc] initWithString:@"http://www.wai.de/emailsJPG/114x120/"];
[temp appendString:[dict objectForKey:@"description"]];
self.imgSrc = temp;
NSURL *imgUrl = [[NSURL alloc] init];
imgUrl = [NSURL URLWithString:@"http://www.wai.de/emailsJPG/114x120/372373.jpg"];
imageLoader = [[ImageLoader alloc] init];
[imageLoader loadImageFromURL:imgUrl withCallbackTarget:self.img withCallbackSelector:@selector(setupImage:)];
}
Code:
- (void) setupImage:(UIImage *) anImage
{
[img setImage:anImage];
}
identifierCounter = [self urlToHashString: anImageURL]; is it ok? thank you for all your help |
|
|
|
0
|
|
|
#28 |
|
The identifier isn't a big deal. I don't even really use it other than to log how many different operations I've made at this point.
I need more information on that error you're receiving. Does it say anything else useful? Could you post the error? You may need to start using some breakpoints or NSLog() to find out where your program is getting to and what is causing the exception if the error doesn't show anything useful. |
|
|
|
0
|
|
|
#29 |
|
this is what appears in the debugger:
Code:
*** -[ImageLoader urlToHashString:]: unrecognized selector sent to instance 0x489ad0 2008-10-17 18:00:25.257 WAIRSS1.2[4783:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[ImageLoader urlToHashString:]: unrecognized selector sent to instance 0x489ad0' |
|
|
|
0
|
|
|
#30 | |
|
Quote:
Code:
@implementation ImageLoader
@synthesize callbackTarget;
@synthesize callbackSelector;
@synthesize imageURL;
static NSOperationQueue *imageLoadingQueue;
static NSMutableDictionary *imageCache;
static NSInteger identifierCounter;
- (void)loadImageFromURL:(NSURL *)anImageURL withCallbackTarget:(id)target withCallbackSelector:(SEL) selector
{
callbackTarget = target;
callbackSelector = selector;
imageURL = anImageURL;
NSLog(@"ImageLoader.m anImageURL = %@", imageURL);
identifierCounter = [self urlToHashString: imageURL];
DataLoaderOperation *op = [DataLoaderOperation queueDataLoadWithURL:imageURL withIdentifier:identifierCounter withCallbackTarget:self withCallbackSelector:@selector(sendImageBack:)];
[imageLoadingQueue addOperation:op];
}
+ (NSString*) urlToHashString:(NSURL*)aURL
{
return [NSString stringWithFormat:@"%U",[[aURL absoluteString] hash]];
}
- (NSData*) dataForURL:(NSURL*)aURL
{
NSLog(@"ImageLoader.m dataForURL %@", aURL);
return [imageCache valueForKey:[ImageLoader urlToHashString:aURL]];
}
- (void) addImageDataToCache:(NSData*)aDatum forURL:(NSURL*)aURL
{
NSLog(@"ImageLoader.m am adaugat in cache imaginea pentru url= %@", aURL);
[imageCache setValue:aDatum forKey:[ImageLoader urlToHashString:aURL]];
}
- (void) sendImageBack:(NSData*)data
{
if (!data) {
return;
}
[data retain];
[self addImageDataToCache:data forURL:imageURL];
UIImage *thisImage = [UIImage imageWithData:data];
if ([callbackTarget respondsToSelector:callbackSelector]) {
[callbackTarget performSelector:callbackSelector withObject:thisImage];
}
}
|
||
|
|
0
|
|
|
#31 | |
|
Quote:
|
||
|
|
0
|
|
|
#32 |
|
this is my ImageLoader.h
Code:
@interface ImageLoader: NSObject
{
id callbackTarget;
SEL callbackSelector;
NSURL *imageURL;
}
@property (assign) id callbackTarget;
@property (assign) SEL callbackSelector;
@property (nonatomic, retain) NSURL *imageURL;
- (void)loadImageFromURL:(NSURL *)anImageURL withCallbackTarget:(id)target withCallbackSelector:(SEL) selector;
- (void) sendImageBack:(NSData *) data;
- (void) addImageDataToCache:(NSData *)aData forURL:(NSURL *) aImageURL;
+ (NSString*) urlToHashString:(NSURL*)aURL;
- (NSData*) dataForURL:(NSURL*)aURL;
|
|
|
|
0
|
|
|
#33 |
|
change the line:
identifierCounter = [self urlToHashString: imageURL]; You can start with just making it identifierCounter = 0; If that doesn't work, you need to identify the line that is throwing that error by putting NSLog()'s before/after all of them or use breakpoints. |
|
|
|
0
|
|
|
#34 | |
|
Quote:
and the line doesn't appear in the console... Code:
- (void) sendImageBack:(NSData*)data
{
if (!data) {
return;
}
NSLog(@"send image back"); //added this to test if the function is called
[data retain];
[self addImageDataToCache:data forURL:imageURL];
UIImage *thisImage = [UIImage imageWithData:data];
if ([callbackTarget respondsToSelector:callbackSelector]) {
[callbackTarget performSelector:callbackSelector withObject:thisImage];
}
}
|
||
|
|
0
|
|
|
#35 |
|
So put NSLog()'s in all of your functions and see what's getting hung up. Seems like standard debugging at this point I would say.
|
|
|
|
0
|
|
|
#36 | |
|
Quote:
NSURL*)anImageURL withIdentifier NSInteger)anIdentifier withCallbackTarget id)aTarget withCallbackSelector SEL)aSelector more exactly NSLog(@"Made an NSOperation withId %d)", anIdentifier); the rest of them do not appear..and this is really wierd.. Last edited by Isorinu'; Oct 17, 2008 at 10:47 AM. |
||
|
|
0
|
|
|
#37 |
|
Alright, I may see the problem.
Here's a tip when debugging, you can do Code:
if (someObject == nil) {
NSLog(@"someObject exists");
}
Code:
NSLog(@"someObject's memory address: <%U>", someObject); Code:
NSLog(@"About to add an op to imageLoadingQueue <%U>", imageLoadingQueue); [imageLoadingQueue addOperation:op]; So now add an init function in ImageLoader: Code:
- (id) init
{
if (self = [super init]) {
if (imageCache == nil) {
identifierCounter = 0;
imageLoadingQueue = [[NSOperationQueue alloc] init];
[imageLoadingQueue setMaxConcurrentOperationCount:2];
}
}
return self;
}
Last edited by youPhone; Oct 17, 2008 at 11:26 AM. |
|
|
|
0
|
|
|
#38 | |
|
Quote:
i made what you said..now the NSLogs that i put in all the functions in ImageLoader, DataLoaderOperation and in my FeedTableViewCell classes appear..but the images aren't changed... ![]() i don't know what tot do next...
|
||
|
|
0
|
|
|
#39 |
|
Is what is being sent back an image? Are you sending the image to a UIImageView and the setImage: to the method?
Wherever you're calling loadImageFromURL:withCallbackTarget:withCallbackSelector: you might want to try changing the selector to a custom function like: Code:
- (void) testCallbackSelector:(UIImage*)image
{
NSLog(@"testCallbackSelector received image with address <%U>", image);
}
Walk through all the steps. Make sure everything is initialized and you're getting what you want at each step. It took me quite a while to get everything working just right. |
|
|
|
0
|
|
|
#40 |
|
Hello guys, could you send a example source code to me that i have the same issue
Hello guys,
Could you send me all of your example codes? because i feel very confused about your talking and uncompleting codes. Your discussion is very helpful for me so I wish I could learn something here from you guys, thanks so much buddies! ![]() ![]() My email is: anim510@gmail.com Thanks again. |
|
|
|
0
|
|
|
#41 |
|
I don't have any example code really.
This person has some example code for doing an NSOperation http://forums.macrumors.com/showthre...ht=nsoperation And then I have modified and built on that as I explain in this thread. Read and understand posts #1 through #19 of this thread and that should be enough to get you going |
|
|
|
0
|
|
|
#42 | |
|
OK, thanks.
Quote:
I will read these posts again.
|
||
|
|
0
|
|
|
#43 | |
|
Hey guys.
Quote:
I have the problem that is every time scrolling the cell lists, it will be lagging. It locks my phone up, because of it downloading the image from the internet. |
||
|
|
0
|
|
|
#44 |
|
Hello again youPhone,
i looked over my code several times and everything stopes in the ImageLoader class when it verifies if the callback target responds to the selector. Code:
- (void) sendImageBack:(NSData*)data
{
NSLog(@"Send image back function. Addres for data: <%U>", data);
if (!data) {
return;
}
NSLog(@"send image back"); //added this to test if the function is called
//[data retain];
NSLog(@"address for data = <%U>", data);
[self addImageDataToCache:data forURL:imageURL];
UIImage *thisImage = [UIImage imageWithData:data];
//UIImage *thisImage = [UIImage imageNamed:@"wai_news_logo_loading.png"];
//NSLog(@"Address for thisImage = <%U>", thisImage);
if ([callbackTarget respondsToSelector:callbackSelector]) {
NSLog(@"sendImageBack inside IF");
[callbackTarget performSelector:callbackSelector withObject:thisImage];
}
//NSLog(@"Address fot thisImage= <%U>", thisImage);
}
Code:
*** -[UIImageView testCallbackSelector:]: unrecognized selector sent to instance 0x4bb0a0 Code:
-(void) testCallbackSelector: (UIImage *) image
{
NSLog(@"testCallbackSelector received image with address <%U>", image);
}
thank you in advance, Sorin |
|
|
|
0
|
|
|
#45 |
|
On the call that looks like this:
Code:
[imageLoader loadImageFromURL:yourURL withCallbackTarget:yourObject withCallbackSelector:@selector(yourMethod:)]; Also, make sure whatever the object is that you're using (yourObject), make sure that 'yourMethod:' is defined by that object, such as adding it to the .h file. If you're still having trouble, post the code that is making the call (it should look similar to the above code). |
|
|
|
0
|
|
|
#46 |
|
thank you for your quick answer youPhone.
My custom UITableViewCell looks like this. Code:
#import <UIKit/UIKit.h>
#import "Feed.h"
#import "ImageLoader.h"
@interface FeedTableViewCell : UITableViewCell {
UILabel *titleLabel;
UILabel *dateLabel;
NSMutableString *URL;
NSMutableString *imgSrc;
UIImageView *img;
ImageLoader *imageLoader;
}
- (void) setData:(NSDictionary *) aFeed;
- (void) testCallbackSelector: (UIImage *) image;
- (void) setupImage:(UIImage *)anImage;
- (UILabel *) newLabelWithPrimaryColor:(UIColor *) primaryColor selectedColor: (UIColor *) selectedColor fontSize:(CGFloat) fontSIze bold:(BOOL) bold;
@property(nonatomic, retain) UILabel *titleLabel;
@property(nonatomic, retain) UILabel *dateLabel;
@property(nonatomic, retain) NSMutableString *URL;
@property(nonatomic, retain) NSMutableString *imgSrc;
@property(nonatomic, retain) UIImageView *img;
@property(nonatomic, retain) ImageLoader *imageLoader;
@end
Code:
#import "FeedTableViewCell.h"
#import "ImageLoader.h"
@implementation FeedTableViewCell
@synthesize titleLabel, dateLabel, URL, imgSrc, img, imageLoader;
...
-(void) setData:(NSDictionary *) dict
{
self.titleLabel.text = [ dict objectForKey:@"title" ];
self.dateLabel.text = [ dict objectForKey:@"pubDate" ];
self.URL = [ dict objectForKey:@"link" ];
NSMutableString *temp = [[NSMutableString alloc] initWithString:@"http://www.wai.de/emailsJPG/114x120/"];
[temp appendString:[dict objectForKey:@"description"]];
// clean up the link - get rid of spaces, returns, and tabs...
temp = [temp stringByReplacingOccurrencesOfString:@" " withString:@""];
temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
temp = [temp stringByReplacingOccurrencesOfString:@"\t" withString:@""];
temp = [[temp componentsSeparatedByString:@"<"] objectAtIndex:0];
NSURL *imgurl = [NSURL URLWithString: temp];
imageLoader = [[ImageLoader alloc] init];
//[imageLoader loadImageFromURL:imgurl withCallbackTarget:img withCallbackSelector:@selector(setupImage:)];
[imageLoader loadImageFromURL:imgurl withCallbackTarget:self.img withCallbackSelector:@selector(testCallbackSelector:)];
}
- (void) setupImage:(UIImage *) anImage
{
NSLog(@"Setup Image in table cell");
UIImage *loadImage = [[UIImage alloc] init];
loadImage = anImage;
[img setImage:loadImage];
}
-(void) testCallbackSelector: (UIImage *) image
{
NSLog(@"testCallbackSelector received image with address <%U>", image);
}
UITableView *)tableView cellForRowAtIndexPath NSIndexPath *)indexPath like this:Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyIdentifier";
FeedTableViewCell *cell = (FeedTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[FeedTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSDictionary *itemAtIndex = (NSDictionary *)[stories objectAtIndex: storyIndex];
[cell setData:itemAtIndex];
return cell;
}
Sorin |
|
|
|
0
|
|
|
#47 |
|
I think this:
Code:
[imageLoader loadImageFromURL:imgurl withCallbackTarget:self.img withCallbackSelector:@selector(testCallbackSelector:)]; Code:
[imageLoader loadImageFromURL:imgurl withCallbackTarget:self withCallbackSelector:@selector(testCallbackSelector:)]; |
|
|
|
0
|
|
|
#48 |
|
Thank you! thank you! thank you! thank you! thank you! thank you! thank you!
you are the best! it's working perfectly! can u please explain why that modification was necessary? thanK you for all your time and patience you made me really happy!
|
|
|
|
0
|
|
|
#49 |
|
In this line:
Code:
[imageLoader loadImageFromURL:imgurl withCallbackTarget:self withCallbackSelector:@selector(testCallbackSelector:)]; The testCallbackSelector is a custom method that you've added to your custom FeedTableViewCell class, therefore you need to call testCallbackSelector on your FeedTableViewCell instance (which is 'self') rather than the UIImageView ('self.img'). |
|
|
|
0
|
|
|
#50 |
|
Great thread, this helped me a lot with making images load smoother in a tableviewcontroller.. (filling it with data through a JSON framework)
I am however running into same issue with the hashtostring function, the debugger gives: Code:
2008-11-17 19:17:38.661 Kookjij-Menus[12588:20b] ImageLoader.m anImageURL = http://static.kookjij.nl//upload//0000/7876/00007876-60x60.jpg 2008-11-17 19:17:38.664 Kookjij-Menus[12588:20b] *** -[ImageLoader urlToHashString:]: unrecognized selector sent to instance 0x3824d0 And what's the best way to unload or cache an image into memory ?, at the moment when a cell is re-used while scrolling, the old image displays until the new one is loaded, this is noticable when scrolling back and forward, this will temporarily display the wrong image in a cell when it pops back into view.. I'm doing a #import DataLoaderOperation.h class from the ImageLoader.m, file, which is in turn called from the ViewImageCell subclass of a TableViewController.., as with the above example it's also called from a setData function and a setupImage function: Code:
-(void)setData:(NSDictionary *)dict {
self.titleLabel.text = [dict objectForKey:@"naam"];
self.urlLabel.text = [dict objectForKey:@"description"];
self.itemID = (int)[dict objectForKey:@"id"];
NSURL *imgUrl = [[NSURL alloc] init];
imgUrl = [NSURL URLWithString:[dict objectForKey:@"image"]];
imageLoader = [[ImageLoader alloc] init];
[imageLoader loadImageFromURL:imgUrl withCallbackTarget:self withCallbackSelector:@selector(setupImage:)];
}
- (void) setupImage:(UIImage *) anImage
{
NSLog(@"Setup Image in table cell");
UIImage *loadImage = [[UIImage alloc] init];
loadImage = anImage;
[imageView setImage:loadImage];
}
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| Raw Disk Image for iPhone 4.3.5 ? | Sharina | Jailbreaks and iOS Hacks | 0 | Aug 30, 2011 04:49 PM |
| How to load remote images in 10.7 Mail? | jackapple | Mac OS X 10.7 Lion | 0 | Jul 20, 2011 03:28 PM |
| How to display remote images if Load Remote images is turned off | Graig | iPad | 1 | Aug 12, 2010 05:50 PM |
| Change background for UITableViewCell | Sergio10 | iPhone/iPad Programming | 4 | Dec 7, 2009 09:33 AM |
| Image for UITableViewCell | sujithkrishnan | iPhone/iPad Programming | 1 | Jul 6, 2009 06:43 AM |
All times are GMT -5. The time now is 04:19 PM.







NSURL*)anImageURL withIdentifier



Linear Mode

