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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:53:29+00:00 2026-06-01T01:53:29+00:00

I am using xcode 4.2 with storyboard to create an iphone app. When I

  • 0

I am using xcode 4.2 with storyboard to create an iphone app.

When I press the edit button in the top right corner I would like to have the options to delete the existing rows and see the extra cell (with the green ‘+’ icon) at the top which would allow me to add a new cell.

I have an array which is being populated in the viewDidLoad method using CoreData

I have enabled the settings button

self.navigationItem.rightBarButtonItem = self.editButtonItem;

And implemented the method

- (void)tableView:(UITableView *)tableView commitEditingStyle:   
          (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:
                   (NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // removing a cell from my array and db here... 
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // adding a cell to my array and db here...
    }   
}

I realise I need to add the cell at some point which I can then edit but it isn’t clear to me where and I am unable to find a explanation on the internet.

  • 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-01T01:53:30+00:00Added an answer on June 1, 2026 at 1:53 am

    Ok, the basic idea is that when the edit button is clicked we’ll show the delete controls next to each row and add a new row with the add control so that users can click it in order to add an entry right? First, since you have the edit button setup already let’s instruct our table that in editing mode we should show an extra row. We do that in our tableView:numberOfRowsInSection:

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.editing ? a_recs.count + 1 : a_recs.count;
    }
    

    a_recs here is the array I’ve setup to store our records so you’ll have to switch that out with your own array. Next up we tell our tableView:cellForRowAtIndexPath: what to do with the extra row:

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *CellIdentifier = @"Cell";
        BOOL b_addCell = (indexPath.row == a_recs.count);
        if (b_addCell) // set identifier for add row
            CellIdentifier = @"AddCell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            if (!b_addCell) {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }
        }
    
        if (b_addCell)
            cell.textLabel.text = @"Add ...";
        else
            cell.textLabel.text = [a_recs objectAtIndex:indexPath.row];
    
        return cell;
    }
    

    We also want to instruct our table that for that add row we want the add icon:

    -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        if (indexPath.row == a_recs.count) 
            return UITableViewCellEditingStyleInsert;
        else
            return UITableViewCellEditingStyleDelete;
    }
    

    Butter. Now the super secret kung fu sauce that holds it all together with chopsticks:

    -(void)setEditing:(BOOL)editing animated:(BOOL)animated {
        [super setEditing:editing animated:animated];
        [self.tableView setEditing:editing animated:animated];
        if(editing) {
            [self.tableView beginUpdates];
            [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:a_recs.count inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
            [self.tableView endUpdates];        
        } else {
            [self.tableView beginUpdates];
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:a_recs.count inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
            [self.tableView endUpdates];
            // place here anything else to do when the done button is clicked
    
        }
    }
    

    Good luck and bon appetit!

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

Sidebar

Related Questions

I've developed an app using xcode 4.2 and storyboard and yesterday when I tried
I am new to iPhone app. I was told not to use Xcode storyboard
I am designing an iOS app using XCode 4.2's storyboard feature. The app has
Why can't XCode 4 create XIB file while using storyboard: is it 2 incompatible
I created a project in xcode 4.2 using the feature of storyboard. I have
Have started playing with Xcode 4.2, and created a single page application using storyboard
If an app is developed using Storyboard in Xcode 4.2, can this app run
Hi there, Now I'm trying to create a Pop-OverView using an Xcode storyboard. Firstly,
Is there a way in Xcode when using the Storyboard in the Interface Builder
I'm using XCode 4.2 and have built my UI using Storyboards. I need to

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.