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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:31:27+00:00 2026-06-03T08:31:27+00:00

i want to create an application in one row of tableView there will be

  • 0

i want to create an application in one row of tableView there will be 4 images of button which will be loaded from server in background because if i directly load them than the table view will hang some. for this i have used this code for creating button in cell and performing to download images in background.

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

        static NSString *hlCellID = @"hlCellID";

        UITableViewCell *hlcell = [tableView dequeueReusableCellWithIdentifier:hlCellID];
        if(hlcell == nil) {
            hlcell =  [[[UITableViewCell alloc] 
                        initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hlCellID] autorelease];
            hlcell.accessoryType = UITableViewCellAccessoryNone;
            hlcell.selectionStyle = UITableViewCellSelectionStyleNone;
        }

        int section = indexPath.section;
        NSMutableArray *sectionItems = [sections objectAtIndex:section];

        int n = [sectionItems count];

        int i = 0, j = 0, tag = 1;
        int x = 10;
        int y = 30;

        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        for (i = 1; i<= n ; i++) //[arr count]
        {
            for(j=1; j<=4;j++)
            {

                if (i>=n) break;
                Item *item = [sectionItems objectAtIndex:i];

                CGRect rect = CGRectMake(x = x, y = y, 68, 65); 
                UIButton *button=[[UIButton alloc] initWithFrame:rect];
                [button setFrame:rect];
                UIImage *buttonImageNormal=[UIImage imageNamed:item.image];
                [button setBackgroundImage:buttonImageNormal    forState:UIControlStateNormal];
                [button setContentMode:UIViewContentModeCenter];
                // set the image to be loaded (using the same one here but could/would be different)
                NSURL *imgURL = [NSURL URLWithString:@"http://londonwebdev.com/wp-content/uploads/2010/07/featured_home.png"];      

                // Create an array with the URL and imageView tag to 
                // reference the correct imageView in background thread.
                NSMutableArray *arr = [[NSArray alloc] initWithObjects:imgURL, [NSString stringWithFormat:@"%d", tag], nil  ];

                // Start a background thread by calling method to load the image
                [self performSelectorInBackground:@selector(loadImageInBackground:) withObject:arr];
    //          button.tag = [tagValue intValue];
                button.tag = tag;
                //NSLog(@"....tag....%d", button.tag);

                [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
                [hlcell.contentView addSubview:button];
                [button release];

                tag++;

                x = x + 77; 

            }
            x = 10;
            y = y + 74;
        }
        [pool release];
        return hlcell;
    }

the above code work perfectly but when i download the images and trying to assign at the some particular button than i can’t find the button tags althoug i can find the button tags while touchupinside action.

- (void) loadImageInBackground:(NSArray *)urlAndTagReference  {

    NSLog(@"Received URL for tagID: %@", urlAndTagReference);

    // Create a pool
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // Retrieve the remote image. Retrieve the imgURL from the passed in array
    NSData *imgData = [NSData dataWithContentsOfURL:[urlAndTagReference objectAtIndex:0]];
    UIImage *img    = [[UIImage alloc] initWithData:imgData];

    // Create an array with the URL and imageView tag to 
    // reference the correct imageView in background thread.
    NSMutableArray *arr = [[NSArray alloc] initWithObjects:img, [urlAndTagReference objectAtIndex:1], nil  ];

    // Image retrieved, call main thread method to update image, passing it the downloaded UIImage
    [self performSelectorOnMainThread:@selector(assignImageToImageView:) withObject:arr waitUntilDone:YES];

    [pool release];

}

    - (void) assignImageToImageView:(NSArray *)imgAndTagReference
    {

        // Create a pool
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        int i;
        UIButton *checkView;

    //  [imagesForCategories addObject:[imgAndTagReference objectAtIndex:1]];
    //    UITableViewCell *cell = [celebCategoryTableView cellForRowAtIndexPath:[imgAndTagReference objectAtIndex:1]];
    //    UIImageView *profilePic = (UIImageView *)[cell.contentView viewWithTag:20];
    //    profilePic.image = [imgAndTagReference objectAtIndex:0];


    //  checkView.tag = [[imgAndTagReference objectAtIndex:1] intValue];
        // loop
        for (UIButton *checkView in [self.tblImage subviews] ) 
        { i++;
            NSLog(@"Checking tag: %d against passed in tag %d",checkView.tag, [[imgAndTagReference objectAtIndex:1] intValue]);
            if ([checkView tag] == [[imgAndTagReference objectAtIndex:1] intValue]) {

                if (i==35) break;
                // Found imageView from tag, update with img
    //          [checkView setImage:[imgAndTagReference objectAtIndex:0]];
                [checkView setImage:[imgAndTagReference objectAtIndex:0] forState:UIControlStateNormal];

                //set contentMode to scale aspect to fit
                checkView.contentMode = UIViewContentModeScaleAspectFit;

                //change width of frame
                CGRect frame = checkView.frame;
                frame.size.width = 80;
                checkView.frame = frame;

            }
        }   

        // release the pool
        [pool release];

        // Remove the activity indicator created in ViewDidLoad()
        [self.activityIndicator removeFromSuperview];

    }

the all code works perfect but i can’t find the table cell subview here for (UIButton *checkView in [self.tblImage subviews] so how to find the subviews of table cell subviews.?

i want to create something like this pls see image.! after that new city will come and just section change the data will show new images in row and cell section.

  • 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-03T08:31:28+00:00Added an answer on June 3, 2026 at 8:31 am

    you may use SDWebImage

    Web Image
    This library provides a category for UIImageVIew with support for remote images coming from the web.

    It provides:

    An UIImageView category adding web image and cache management to the Cocoa Touch framework
    An asynchronous image downloader
    An asynchronous memory + disk image caching with automatic cache expiration handling
    A guarantee that the same URL won’t be downloaded several times
    A guarantee that bogus URLs won’t be retried again and again
    Performances!

    just use it

    [youImageView setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil options:SDWebImageRetryFailed];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create application which would display spatial data on Map. I'm thinking
I want to create an application which main window has canvas (or something where
I want to create an application for Android that will be able to scan
I want ot create database table in which I can store application settings. Which
I am developing a small application in which I want to create 20 radio
I have created one application in which if i select on particular row in
I created one application, its working fine. I want to support my application in
I want to create windows application in c# 2008. The problem is I don't
I want to create an application like this: http://collabedit.com/ What is the most efficient
I want to create an application that doesn't use Portrait mode. I am not

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.