Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:21:47+00:00 2026-06-15T06:21:47+00:00

I have a view controller with a table view. in each cell of the

  • 0

I have a view controller with a table view. in each cell of the table view, i have an image which is fetched from the net – but many of them have the same image. so, what i’m doing currently is storing the fetched images in a NSCache object. it happens this way:

- (void)fetchAvatarForUser:(NSString *)uid completion:(void (^)(BOOL))compBlock
{
if (!imageCache) {
    imageCache = [[NSCache alloc] init];
}
if (!avatarsFetched) {
    avatarsFetched = [[NSMutableArray alloc] initWithCapacity:0];
}

if ([avatarsFetched indexOfObject:uid] != NSNotFound) {
    // its already being fetched
} else {
    [avatarsFetched addObject:uid];
    NSString *key = [NSString stringWithFormat:@"user%@",uid];

    NSString *path = [NSString stringWithFormat:@"users/%@/avatar",uid];
    [crudClient getPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@",[operation.response allHeaderFields]);
        UIImage *resImage = [UIImage imageWithData:[operation responseData]];
        [imageCache setObject:resImage forKey:key];
        compBlock(YES);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Got error: %@", error);
        compBlock(NO);
    }];
}
}

- (UIImage *)getAvatarForUser:(NSString *)uid
{
NSString *key = [NSString stringWithFormat:@"user%@",uid];
NSLog(@"Image cache has: %@",[imageCache objectForKey:key]);
return [imageCache objectForKey:key];

}

imageCache is an instance variable, and also avatarsFetched, crudClient is an AFHTTPClient object.
and, in the table view:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    static NSString *CellIdentifier = @"Cell";

    PostCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[PostCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    Post *curPost = [displayedPosts objectAtIndex:indexPath.section];

    cell.nickname.text = [curPost nickname];

    UIImage *avatarImage = [self.delegateRef.hangiesCommunicator getAvatarForUser:curPost.userID];
    if (avatarImage) {
        cell.avatar.image = avatarImage;
        NSLog(@"Its not null");
    } else {
        cell.avatar.image = [UIImage imageNamed:@"20x20-user-black"];
    }
}

self.delegateRef.hangiesCommunicator returns the object (which is a retained property of the app delegate) with the imageCache as an instance variable, and the two methods at the top.

When i scroll, i see the @”Its not null” in the console, yet i don’t see the fetched image but the default 20×20-user-black image. does anybody have an idea, why is this happening? what am i doing wrong?

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:21:49+00:00Added an answer on June 15, 2026 at 6:21 am

    Your code is missing some things. I can’t see where you ever call the fetchAvatarForUser:completion: method on your hangiesCommunicator and your tableView:cellForRowAtIndexPath: method is not returning the cell, so I don’t think the code you posted will compile cleanly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UI Table View Controller. Each Cell Loads an image from my
Well I do have a table view controller and is each cell I have
I have a Dynamic table view which has 5 prototype cells, inside each cell
I have a table view controller with (among others) a cell that is to
I have a table view controller which doesn't let me manually scroll to the
I have table view navigation controller and the data is loaded from url. I
I have a table view of custom cells representing individual uploads and each cell
I have created a table view that pulls its cells from an array. Each
I have view controller, into the view i have put a table view, and
I have a Table View Controller with cells. I want to update the text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.