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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:30:34+00:00 2026-05-23T09:30:34+00:00

In my app i have a table view displaying images view ,,4 image view

  • 0

In my app i have a table view displaying images view ,,4 image view in one row .My issue is that after loading the table view with some data then if i try to scroll the table view then my app is crashing.On using the breakpoint i found that cell for row at index path methid is called again and my array tries to reload data again.Please help as its getting on my head now,i am posting my code here:–

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

    UITableViewCell *cell = nil;



    static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";

    cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];


        UIImageView * imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 70, 80)] autorelease];

        UIImageView * imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,70, 80)] autorelease];

        UIImageView * imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 70, 80)] autorelease];

        UIImageView * imageView4 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 70, 80)] autorelease];

        UIImageView * imageView5 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 70, 80)] autorelease];

        UIImageView * imageView6 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,70, 80)] autorelease];

        UIImageView * imageView7 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 70, 80)] autorelease];

        UIImageView * imageView8 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 70, 80)] autorelease];

        UIImageView * imageView9 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 70, 80)] autorelease];

        UIImageView * imageView10 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,70, 80)] autorelease];

        UIImageView * imageView11 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 70, 80)] autorelease];

        UIImageView * imageView12 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 70, 80)] autorelease];



        imageView1.tag=1;
        imageView2.tag=2;
        imageView3.tag=3;
        imageView4.tag=4;
        imageView5.tag=5;
        imageView6.tag=6;
        imageView7.tag=7;
        imageView8.tag=8;
        imageView9.tag=9;
        imageView10.tag=10;
        imageView11.tag=11;
        imageView12.tag=12;



        if ([sentence count]>0) {

            [imageViewArray insertObject:imageView1 atIndex:0];

            [cell.contentView addSubview:imageView1];

        }

        if ([sentence count]>1) {

            [imageViewArray insertObject:imageView2 atIndex:1];

            [cell.contentView addSubview:imageView2];

        }

        if ([sentence count]>2) {

            [imageViewArray insertObject:imageView3 atIndex:2];

            [cell.contentView addSubview:imageView3];
        }

        if ([sentence count]>3) {

            [imageViewArray insertObject:imageView4 atIndex:3];

            [cell.contentView addSubview:imageView4];
        }
        if ([sentence count]>4) {
            [imageViewArray insertObject:imageView5 atIndex:4];

            [cell.contentView addSubview:imageView5];
        }
        if ([sentence count]>5) {
            [imageViewArray insertObject:imageView6 atIndex:5];

            [cell.contentView addSubview:imageView6];
        }
        if ([sentence count]>6) {
            [imageViewArray insertObject:imageView7 atIndex:6];

            [cell.contentView addSubview:imageView7];
        }
        if ([sentence count]>7) {
            [imageViewArray insertObject:imageView8 atIndex:7];

            [cell.contentView addSubview:imageView8];
        }
        if ([sentence count]>8) {
            [imageViewArray insertObject:imageView9 atIndex:8];

            [cell.contentView addSubview:imageView9];
        }
        if ([sentence count]>9) {
            [imageViewArray insertObject:imageView10 atIndex:9];

            [cell.contentView addSubview:imageView10];
        }
        if ([sentence count]>10) {
            [imageViewArray insertObject:imageView11 atIndex:10];

            [cell.contentView addSubview:imageView11];
        }
        if ([sentence count]>11 || ([sentence count]==12)) {
            [imageViewArray insertObject:imageView12 atIndex:11];

            [cell.contentView addSubview:imageView12];
        }

    }

        if ([sentence count]!=0) 
{


    int photosInRow;

        if ( (indexPath.row < 

[tableView numberOfRowsInSection:indexPath.section] - 1) || ([sentence count] % 4 == 0) ) {

        photosInRow = 4;

    } else {

        photosInRow = [sentence count] % 4;
    }


    for ( int i = 1; i <=photosInRow ; i++ ){

        imageView = (UIImageView *)[cell.contentView viewWithTag:j];

        [self setImage1:imageView];
        }

    }
        return cell;


}
  • 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-23T09:30:35+00:00Added an answer on May 23, 2026 at 9:30 am

    I believe the biggest problem here is the memory leaks for you imageViews. Each cell creates 12 imageViews, none of which is released. It seems that you should only create the imageViews you need (for speed), and release them correctly (for memory management).

    One way to begin to rewrite this code, is the following:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
    
        if (!cell) {
    
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];
    
            for (int i=0; i <= [sentence count]; ++i) {
                UIImageView * imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(25+90*(i%4), 4, 70, 80)] autorelease];
                imageView.tag = i+1;
                [cell.contentView addSubview:imageView];
                [imageView release];
            }
        }
        return cell;
    }
    

    I don’t understand why you are setting imageViewArray or imageView1 repeatedly. Also, this line:

       imageView = (UIImageView *)[cell.contentView viewWithTag:j];
    

    makes no sense as j is not defined.

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

Sidebar

Related Questions

I have one table view within the app that I hope multiple parts of
I have this .NET web app that draws a table in Page_Load. Then after
So I have a table view that contains a bunch of data. The user
in my app i have a table view and i am adding 4 image
i have a table view that when the user taps on one of the
I'm using Google App Engine and Django templates. I have a table that I
I have an app that needs to check a database table every minute. The
In my App, I have a table view with cell style value2: (cell have
I have an iPhone app, where I'm displaying a tableview, that's loaded from an
In my app i have two view controllers and have table view in both.Both

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.