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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:33:05+00:00 2026-06-18T07:33:05+00:00

I am quite new to iOS development and I’m facing a multithreading issue. I’m

  • 0

I am quite new to iOS development and I’m facing a multithreading issue.

I’m using KTPhotobrowser with SDWebImage to create a photo and video gallery.
I have to load some external data on each picture, and I don’t want to affect the smoothness of the gallery’s scroll view.

So, I’m trying to do that using NSOperation and NSOperationQueue, but I’m not sure I’m doing right.

What I want is to stop the loading process if the user doesn’t stay on the picture and keep scrolling.

My current code:

//setCurrentIndex is called when the scrollView is scrolled

- (void)setCurrentIndex:(NSInteger)newIndex {

   [loadingQueue_cancelAllOperations]; 
   currentIndex_ = newIndex;
   [self loadPhoto:currentIndex_];     
   NSInvocationOperation *InvocationOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadInfosAtIndex:) object:newIndex];

   [loadingQueue_ addOperation:InvocationOp];      
   [InvocationOp release];

   [selfloadPhoto:currentIndex_ + 1];
   [selfloadPhoto:currentIndex_ - 1];
   [selfunloadPhoto:currentIndex_ + 2];
   [selfunloadPhoto:currentIndex_ - 2]; 
}

-(void) loadInfosAtIndex:(NSInteger)index {

   if (index < 0 || index >= photoCount_) {
        return;
   }

   KTPhotoView* photoView = [photoViews_ objectAtIndex:index];
   if([photoView infosAlreadyLoaded]){
       NSLog(@"%d Already Loaded", index);
       return;
   }

    //Get the extra information by calling a web service
    photoView.infosAlreadyLoaded = YES;
}

I don’t think this is the proper way to do this… has anyone got any advice?

  • 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-18T07:33:07+00:00Added an answer on June 18, 2026 at 7:33 am

    Instead of relying on a scheduling-based cancel, which can leave you in an uncertain state, have a cancelling instance variable that has atomic access (either via an atomic property or a BOOL ivar with a mutex).

    Then, instead of [loadingQueue_cancelAllOperations], you simply set the canceling flag to YES and check it in loadInfosAtIndex periodically. This is essentially polling for the cancel, and if the code is involved, it can be a pain. But it has the advantage of letting you be able to handle the cancel gracefully by reading the flag. As a part of handling, you can set an isRunning flag (also needs to be atomic/mutexed) to NO and exit the thread by returning.

    In the main thread, after setting the cancelling flag to YES, you can wait till the isRunning flag is NO before opening up a new thread.

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

Sidebar

Related Questions

I'm new to xcode and ios development. I'm learning using Brad Larson online courses.
I am quite new to iOS development and just thought to take guidance from
I am quite new to iOS development and trying hard to develop an App.
Sorry for quite a dumb question, I'm new to iOS development. I'm making an
I'm new to IOS development, and want to create something with tiles similar to
I'm new to OpenGL ES, but quite experienced with Objective-C and iOS development. I've
I am quite new to IOS development, so forgive me if this problem turns
I´m quite new to iOS development and I´m having a terrible time by trying
I'm quite new to iOs Programming.. At the moment I'm wondering about following issue.
I'm quite new here. I have a problem with the new iOS 5.1 slide-in

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.