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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:01:19+00:00 2026-05-15T23:01:19+00:00

I created sample tableview application and I have an add button above the tableview,

  • 0

I created sample tableview application and I have an add button above the tableview, when user pressed the add button only we want to add row to table view.

I am write code like this

- (void)viewDidLoad {
    isEditing = NO;
    Mutarray = [[NSMutableArray alloc]init];
    [super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section       {
// Return the number of rows in the section.
    if (isEditing)
        return [Mutarray count];
    else
        return 0;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    [TableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    NSLog(@"Row = %d", indexPath.row);
// Configure the cell...
    cell.textLabel.text = [Mutarray objectAtIndex:indexPath.row];
    return cell;
}

//When add button pressed

-(IBAction)Add:(id)sender
{   
    isEditing = YES;

    [Mutarray addObject:[NSString stringWithFormat:@"%d",[Mutarray count]]];

    NSArray *insertIndexPaths = [NSArray arrayWithObjects:
                    [NSIndexPath indexPathForRow:[Mutarray count]-1 inSection:0],
                             nil];

    [self.TableView beginUpdates];
    [self.TableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationRight];
    [self.TableView endUpdates];
}

This code works fine.But problem is my tableview height is 418 , it shows only 10 row as visible. So when the 11 row was added it added in tableview but not calling this cellForRowAtIndexPath function so I’m not able to auto scroll the page… The first 10 row it calls the cellForRowAtIndexPath function.

So what I my doubts is why the cellForRowAtIndexPath function only calls visible rows?
Then how can I auto scroll my tableview?

  • 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-15T23:01:20+00:00Added an answer on May 15, 2026 at 11:01 pm

    So what I my doubts is why the
    cellForRowAtIndexPath function only
    calls visible rows ?

    It is so for optimization reasons. If table view had created cells for all its rows it could downgrade performance dramatically. Instead of that table view creates cells only for rows that are visible (and probably a couple more to ensure smooth scrolling) and then reuses them for rows that become visible – so actually you can show hundreds of row with just, say, 10 cell objects – it is a huge save.

    Then how can I auto scroll my
    tableview ?

    You can scroll right after you added a row in your add method:

        ...
        [table endUpdates];
    
        [table scrollToRowAtIndexPath:[insertIndexPaths objectAtIndex:0]
               atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }
    

    P.S. conventionally method and variable names in objective-c start with lowercase, it is better style to follow that guideline.

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

Sidebar

Related Questions

I am new to iphone development.I have created a view based application.Now i want
I have created sample application that insert 12 rows in tableview.And inserted fine.When after
i am working on one application in which i have created one table view
I have created programme in which we navigate from table view to a simple
I have created a sample java socket application. I used Socket s = new
I have followed this tutorial http://blogs.wrox.com/article/creating-a-simple-ipad-application-table-view/ (creating a uitableview and populating it). I want
i have created a simple table view containg an image on the left side
I created a sample application using Android TextView with shared preferences . In my
I have created a sample report with crystal report 10. Now, I wanna to
I want to create a landscape view with 2 table views side by side,

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.