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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:08:34+00:00 2026-06-15T21:08:34+00:00

I have a tableview in which i am loading the cells from 2 different

  • 0

I have a tableview in which i am loading the cells from 2 different custom classes.and my code looks like this

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier1 = @"CellIdentifier";
        static NSString *CellIdentifier2 = @"Cell";
            
        if(messagesarray==nil||[messagesarray count]==0)
        {
            
        }
        else
        {
            NSMutableDictionary *dicttable=[messagesarray objectAtIndex:indexPath.row];
            NSString *head=[dicttable objectForKey:@"gfgfg"];
            NSString *head1=[dicttable objectForKey:@"gfgfgf"];
            if([type isEqualToString:@"m"])    
            {
                if([head isEqualToString:@"NA"])
                {
                 
                    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
                    if (cell == nil)
                    {
                        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier1] autorelease];
                        cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"white_top_portion.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];
                    }
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.nameLabel.text=head;
                    cell.msg.text=head1;
                    [cell.button addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];     
                  
                    if(icon!=nil)
                    {
                        if(![[ImageCache sharedImageCache] hasImageWithKey:icon])
                        {
                            cell.myImageView.image = [UIImage imageNamed:@"fggtgf.png"];
                            NSArray *myArray = [NSArray arrayWithObjects:cell.myImageView,icon,@"fgfgfg.png",[NSNumber numberWithBool:NO],nil];
                            AppDelegate *appDelegate = (AppDelegate  *)[[UIApplication sharedApplication] delegate];
                            [appDelegate performSelectorInBackground:@selector(updateImageViewInBackground:) withObject:myArray];   
                        }
                        else 
                        {
                            cell.myImageView.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:icon];
                        }
                    }
                    else
                    {
                        cell.myImageView.image = [UIImage imageNamed:@"fgfgfg.png"];  
                      
                    } 
             
                    cell.label.text=sub;   
                    return cell;
                }
                else
                {
                    Customcellwithimage *cell = (Customcellwithimage *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
                 
                    if (cell == nil)
                    {
                        cell = [[[Customcellwithimage alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier2] autorelease];
                        cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"white_deal_bg.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];
                    }
                 
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.datelabel1.text=subtitle;
                    cell.nameLabel1.text=head;
                    cell.msg1.text=head1;
                    if(icon!=nil)
                    {
                        if(![[ImageCache sharedImageCache] hasImageWithKey:icon])
                        {
                            cell.myImageView1.image = [UIImage imageNamed:@"fgfgfgf.png"];
                            NSArray *myArray = [NSArray arrayWithObjects:cell.myImageView1,icon,@"fgfgfgf.png",[NSNumber numberWithBool:NO],nil];
                            MFAppDelegate *appDelegate = (MFAppDelegate  *)[[UIApplication sharedApplication] delegate];
                            [appDelegate performSelectorInBackground:@selector(updateImageViewInBackground:) withObject:myArray];   
                           
                        }
                        else 
                        {
                            cell.myImageView1.image = [[ImageCache sharedImageCache] getImagefromCacheOrUrl:icon];
                        }
                    }
                    else
                    {
                        cell.myImageView1.image = [UIImage imageNamed:@"fgfgfgf.png"];  
                    } 
                  
                    cell.cellview1.image=[UIImage imageNamed:@"vf.png"];
                    cell.label1.text=sub;
                    [cell.button1 addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside]; 
                    cell.bannerview1.image=[UIImage imageNamed:@"vfgf.png"];
                    return cell;
                }   
            }                 
        }  
    }

My problem is only the first element in the array is priting repeatedly in the cells(cells repeating),can anybody help me to know why this is happening.I have array count number of sections and each section having only single row.

  • 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-15T21:08:35+00:00Added an answer on June 15, 2026 at 9:08 pm

    If each section only has a single row, then indexPath.row will be 0 every time this method is called. Since the row is what you use to choose an array element, it’s reasonable that it will always be the same one.

    You need to use indexPath.section instead if you’re returning [messagesarray count] for the number of sections and 1 for the number of rows.

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

Sidebar

Related Questions

I have an iphone application in which I'm loading a UITableView from 3 types
I have a UITableView which loads data from XML using the below code. It
I have a TableView loading a custom cell and loading the data from a
I have a UITableView which loads through it's navigationController a new viewcontroller. This code
guys, I have UITableView with some images, which are loading from internet. Images is
I have a tableView which has cells with phone numbers. The app is not
In a tableview I have on every cell a UILongPressGestureRecognizer which I add like
I have a Table View which displays images using lazy loading from AFNetworking with
I have a UITableView which is displaying update posts from various social networks. I
In the Xcode I have like this: In a MyViewController.m I am loading the

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.