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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:54:33+00:00 2026-05-23T05:54:33+00:00

im new to xcode and i am doing this code to fill up the

  • 0

im new to xcode and i am doing this code to fill up the table view with annotation titles but the function gets called more than once and the table cells are filled with all repeated values , how is the function called in xcode , how can i stop this function from getting called more than once

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSLog(@"this is a test text            ");
    NSMutableArray *annotations = [[NSMutableArray alloc] init];
    int i=0;
    if(indexPath.section == 0)
    {
        for(iCodeBlogAnnotation *annotation in [map annotations])
        {
            i++;
            NSLog(@"this is the no %d",i);
            [annotations addObject:annotation]; 
        }

        cell.textLabel.text = [[annotations objectAtIndex:indexPath.row] title];
    }

    return cell;
}

Any help would be deeply appreciated ,
Thank you for your help in advance

  • 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-23T05:54:33+00:00Added an answer on May 23, 2026 at 5:54 am

    You can’t really control when it’s called. It’s called each time your tableview wants to display a new cell. You use the indexPath to determine what to put in that cell. It’s called at least once per cell that’s on the screen (sometimes more if the table is scrolled up and down).

    You don’t need to create the temporary array each time this function is called, just use [map annotations] directly :

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // There will be one row per annotation
        return [[map annotations] count]
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {    
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil) 
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    
        // Put the text from this annotation into this cell
        cell.textLabel.text = [[[map annotations] objectAtIndex:indexPath.row] title];
    
        return cell;
    }
    

    I hope I’ve understood your question. If not, please tell me in the comments below!

    • 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 4.2 and have a Storyboard array question. I'm doing a
I updated to new Xcode 4.2 (for iOS 5), but now my project doesn't
When creating a new outlet in Xcode 4 it enters the necessary code like
New here (this forum and Xcode in general), so bear with me. I've spent
I JUST started a new XCode Project. The code I have added in so
NEW INFO: Something I just noticed (because this isn't something I'd normally do), but
I had asked a question similar to this before, but I have a new
Try this: Make a new XCode4 Applescript project. In the delegate, paste this code:
I just created a new Xcode project. In the AppControl class Header file I
I thought I was doing the right thing here but I get several warnings

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.