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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:30:16+00:00 2026-06-14T01:30:16+00:00

i make a custom UITableViewCell: SListViewCell * cell = nil; // cell = [listView

  • 0

i make a custom UITableViewCell:

 SListViewCell * cell = nil;
//    cell = [listView dequeueReusableCellWithIdentifier:CELL];
if (!cell) {
    cell = [[[SListViewCell alloc] initWithReuseIdentifier:CELL] autorelease];
}
listView.separatorColor = [UIColor clearColor];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tag = index;
[btn setFrame:CGRectMake(0, 0, 42, 42)];
//setBtnImage will download image from network. when the UIButton click it is will change button image 
[self setBtnImage:index btn:btn];
[btn addTarget:self action:@selector(typeTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btn];
return  cell;

typeTapped method:

-(void)typeTapped:(id)sender
{
   UIButton* btn = (UIButton)sender;
   //download image from network in ohter thread and change button' image.
   NSThread * thread = [Thread alloc] initWith:@selecter(downloadImage:)....
   [thread start];
   [thread release];
}
//download image 
-(void)downloadImage:(UIButton*)btn....
{
  //download
  UIImage* image= ....
  //UITableView is not update
  //it is will update when i scroll tableview.
  [btn setImage:image ......];
}

so how can i update UITableViewCell in other thread.(if i call reloadDate it is will drop-dead halt)(i can scroll tableview to update it)

  • 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-14T01:30:17+00:00Added an answer on June 14, 2026 at 1:30 am

    You can do most of your processing in the background but anything that updates the UI has to happen on the main thread.

    Doing background processing and then updating the UI can be done easily using Grand Central Dispatch (GCD).

    - (void)typeTapped:(id)sender
    {
        UIButton* btn = (UIButton*)sender;
        // Use Grand Central Dispatch to do the processing in the background.
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
            // Do download operation here... Something like:
            NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://some_url.com/some.image"]];
            UIImage* image = [UIImage imageWithData:imageData];
    
            //Go back to the main thread to update the UI. this is very important!
            dispatch_async(dispatch_get_main_queue(), ^{
                [btn setImage:image forState:UIControlStateNormal];
            });
        });
    }
    

    However. In a table view there’s a couple of gotchas.

    Table cells are re-used. This mean that your nice UIButton in your UITableViewCell may not be the one you think it is once the download has completed. It’s the same object, but has been reconfigured to display the content from another row.

    For these case your best bet is to use GCD to update the NSArray or other data structure is feeding from and then ask the table view to do the refresh for the cell.

    // In the UITableViewDelegate.

    @implementation SomeViewController
    {
      NSMutableArray* _tableData;
    }
    
    // ...
    
    // Someone tapped on the cell.
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
            // Do download operation here... Something like:
            NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://some_url.com/some.image"]];
            UIImage* image = [UIImage imageWithData:imageData];
            if([_tableData count] < indexPath.row) {
                _tableData[indexPath.row] = image;
            }
            //Go back to the main thread to update the UI. this is very important!
            dispatch_async(dispatch_get_main_queue(), ^{
                [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            });
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have subclassed UITableViewCell to make a custom cell for a tableView. I add
I'm trying to make a custom UITableViewCell as I need to have specific control
I want to make a custom UITableViewCell programmatically. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self
I've created a custom UITableViewCell and each cell is passed a custom subclass of
I am using a Custom UITableViewCell and this cell contains round rect. This round
i have make a custom cell in nib file with delegate. I have define
I'm trying to make a custom cell using storyboard. I have tested my program
I’ve made a custom uitableviewcell . The cell consist out of labels and a
I'm trying out this nice way of customizing grouped UITableViewCell backgrounds: http://code.coneybeare.net/how-to-make-custom-drawn-gradient-backgrounds I've implemented
Hi guys I'm unable to make the image file the custom uitableview cell i

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.