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 3213576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:57:38+00:00 2026-05-17T14:57:38+00:00

I have an app that loads multiple thumbnail images into a UIScrollVIew. This is

  • 0

I have an app that loads multiple thumbnail images into a UIScrollVIew. This is a lengthy operation, and so as not to block up the display of the rest of the UI, I am running it in a separate thread. This works fine the first time at application launch, but later a new set of images needs to be loaded into the UIScrollView. When I detach a thread a second time the app crashes (sometimes). Code follows:

// this call is in a separate method
[NSThread detachNewThreadSelector:@selector(addThumbnailsToScrollView) toTarget:self withObject:nil];


// this is the main entry point for the thread
- (void) addThumbnailsToScrollView {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool

// now place all the thumb views as subviews of the scroll view 
float xPosition = THUMB_H_PADDING;
int pageIndex = 0;
for (Page *page in self.pages) {

    // get the page's bitmap image and scale it to thumbnail size
    NSString *name = [page valueForKey:@"pageBackground"];
    NSString *basePath = [[NSBundle mainBundle] pathForResource:page.pageBackground ofType:@"jpg" inDirectory:nil];
    UIImage *thumbImage = [UIImage imageWithContentsOfFile:basePath];
    thumbImage = [thumbImage imageScaledToSize:CGSizeMake(80, 100)];

    // create a ThumbImageView for each page and add it to the thumbnailScrollView
    if (thumbImage) {
        ThumbImageView *thumbView = [[ThumbImageView alloc] initWithImage:thumbImage];
        [thumbView setDelegate:self];
        [thumbView setImageName:name];
        [thumbView setImageSize:CGSizeMake(80, 100)];
        [thumbView setPageIndex:pageIndex];
        pageIndex ++;
        CGRect frame = [thumbView frame];
        frame.origin.y = 0;
        frame.origin.x = xPosition;
        [thumbView setFrame:frame];
        [thumbnailPagesScrollView addSubview:thumbView];
        [thumbView release];
        xPosition += (frame.size.width + THUMB_H_PADDING);
    }
}

[self hightlightThumbnailPageAtIndex:0];
[(UIActivityIndicatorView *)[thumbnailPagesScrollView.superview viewWithTag:100] stopAnimating];

[pool release];  // Release the objects in the pool.
}

I thought that a detached thread exits as soon as the main entry routine was completed. Wouldn’t the second call to detach a thread be a new thread? Why is the app crashing, but sometimes not?

Thanks

Jk

  • 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-05-17T14:57:38+00:00Added an answer on May 17, 2026 at 2:57 pm

    You cannot touch UIKit (meaning UIScrollVIew) in a secondary thread – you need to reorganize so that the fetch takes place in a secondary thread but you make a NSData object (containing the image binary) available to your primary thread for each thumbnail so that it can do everything related to actually displaying them.

    Apple repeatedly warn in documentation that UIKit is not thread-safe.

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

Sidebar

Related Questions

I have a Grails app that loads its data from xml files and delivers
I have an app that when I click a button loads a new TabItem
I have a Cordova app that runs the jQuery mobile framework and loads pages
I have a flash app that plays movies. It loads subtitles and subtitle times
I have an app that loads records from a binary log file and displays
We have a GWT app that has multiple screens, based off of a menu.
I have an app that supports multiple brands, each having their own color scheme,
I am developing app that has multiple skins and I have a dilemma on
I currently have a Rails 3.1 app that hosts multiple sites for several different
I have an app that starts with a tableview (from a xib) that loads

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.