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

  • SEARCH
  • Home
  • 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 8859311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:01:41+00:00 2026-06-14T15:01:41+00:00

I have a db where items are stored. These items can be different kinds

  • 0

I have a db where items are stored. These items can be different kinds of type like text, videos and images. When the View is loaded I fetch these items from the DB and I show them in a UITableView. The problem I am facing is related to show the images in the table view. Basically in the DB I store the ALAsset link related to the picture and from it I try to get its image using this code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

 //...Other Code

  else if ([object isMemberOfClass:[Picture class]]){

            //Get a reusable cell
            cell = [tableView dequeueReusableCellWithIdentifier:@"pictureCellIdentifier"];

            // [self performSelectorInBackground:@selector(performAsset:) withObject:dict];

            ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
            {
                ALAssetRepresentation *rep = [myasset defaultRepresentation];
                CGImageRef iref = [rep fullResolutionImage];
                if (iref) {
                    ((PictureViewCell *)cell).placeHolderImageView.hidden = YES;
                    ((PictureViewCell *)cell).pictureImageView.image =  [UIImage imageWithCGImage:[rep fullResolutionImage]  scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];

                }
            };


            ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
            {
                 [Utility showAlertViewWithTitle:@"Location Error" message:@"You must activate Location Services to access the photo" cancelButtonTitle:@"Dismiss"];

            };

            ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
            [assetslibrary assetForURL:[NSURL URLWithString:((Picture *)objectInArray).imagePath]
                           resultBlock:resultblock
                          failureBlock:failureblock];

         //Set the background for the cell
            cell.backgroundView = iv;

        }

 //...Other code

}

The problem is that when you slide through the cell the method gets called and the app is really slow. So I guess there are better ways to achieve what I’m trying to do. I also tried to perform that code using performselectorInBackground:. Performance seem better but It takes more time to fetch the image.

Any helps would be really appreciated.

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-14T15:01:42+00:00Added an answer on June 14, 2026 at 3:01 pm

    There are a few things that can be improved here.

    The first is as you figured out: Do the loading of the assets in background thread and then add the image to the cell when it is ready on the main thread. Next, you are creating an object of ALAssetsLibrary for every cell that you show. Ideally, an app should have just one object of ALAssetsLibrary that you retain as long as you need it. Create a ALAssetsLibrary the first time you need and then reuse it.

    - (ALAssetsLibrary *)defaultAssetsLibrary {
        if (_library == nil) {
            _library = [[ALAssetsLibrary alloc] init];
        }
        return _library;
    }
    

    And the last, you are using the fullResolutionImage in a tableview cell. If you really just need to display the image, a thumbnailImage or at least a fullScreenImage should be good enough.

    - (void) loadImage:(NSNumber *)indexPath url:(NSURL*)url
    {
        int index = [indexPath intValue];
    
        ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
        {
            CGImageRef iref = [[myasset defaultRepresentation] fullScreenImage];
            if (iref) {
                // TODO: Create a dictionary with UIImage and cell indexPath
    
                // Show the image on main thread
                [self performSelectorOnMainThread:@selector(imageReady:) withObject:result waitUntilDone:NO];
            }
        };
        ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
        {
             [Utility showAlertViewWithTitle:@"Location Error" message:@"You must activate Location Services to access the photo" cancelButtonTitle:@"Dismiss"];
    
        };
    
        [[self defaultAssetsLibrary] assetForURL:url
                       resultBlock:resultblock
                      failureBlock:failureblock];
    }
    
    -(void) imageReady:(NSDictionary *) result
    {
        // Get the cell using index path
    
        // Show the image in the cell
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If i have items stored in a database that users can download after they
I have stored the XML path to items in a string like this: response->items->item
I have an application where users can store items. Now each type of account
I have 2 different object types stored in RavenDb, which are a parent/child type
I'm planning to have collection of items stored in a TCollection. Each item will
I have a table of items stored this way : A1 | B1 A1
I have stored the indexes of comboBox items in to array. Now when I
If I have, say, 100 items that'll be stored in a dictionary, should I
In my process, I have a page that the user can select various items
I have a bunch of menu items in a list format like so <ul

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.