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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:30:40+00:00 2026-06-14T16:30:40+00:00

I had a working tableview where I could double-tap a cell and it would

  • 0

I had a working tableview where I could double-tap a cell and it would add an ‘action’ cell below which had four buttons programmed on it.
Today I added alphabetic sections to the tableview and a section index and I can no longer get this functionality to work.
I’ve added a whole range of NSLogs to the code to try and find the problem and I can’t, it seems to be trying to add a row in the same section and one row further down than the cell tapped, so I’m not sure what the problem is. Would anyone have any idea what I’m doing wrong?
If anyone can shed any light on this I would be hugely appreciative. (And apologies if my code is cumbersome or hard to follow, I’m new to this so feel free to suggest what I can improve!)

- (void)viewDidLoad
     {
     //I start with an array of objects, so I created two arrays; one containing the first letters of each Name, and a list of the number of objects that start with each of those names.
   nameIndex = [[NSMutableArray alloc] init];
   nameIndexCount = [[NSMutableDictionary alloc]init];   
    }

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
     {
     return [nameIndex count];
      }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
     {
     if (self.actionRowIndexPath) {

     //Returns first letter of the section
     NSString *alphabet = [nameIndex objectAtIndex:section];

     //Returns the number of entries starting with that letter
    NSString *numberofRows = [nameIndexCount objectForKey:alphabet];
    int intNumberOfRows = ([numberofRows integerValue] + 1);

    return intNumberOfRows;
} else {

    NSString *alphabet = [nameIndex objectAtIndex:section];

    NSString *numberofRows = [nameIndexCount objectForKey:alphabet];
    int intNumberOfRows = [numberofRows integerValue];

    return intNumberOfRows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"newTableViewCell"];

    if (!cell) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"newTableViewCell"];
    }
    //Configure the cell
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:cell.frame];
    UIImage *image = [UIImage imageNamed:@"LightGrey.png"];
    imageView.image = image;

    if ([indexPath isEqual:self.actionRowIndexPath]) {


        // Four UIButtons coded programmatically

    } else {


        Contact *p = [[[ContactStore sharedStore]allContacts]objectAtIndex:totalNumberOfRows];
        NSString *firstAndLastName = [NSString stringWithFormat:@"%@ %@", [p firstName], [p lastName]];
        indexPath = [self modelIndexPath:indexPath];
        cell.backgroundView = imageView;
        //        [cell.imageView setImage:smallThumbnailImage];
        [cell.imageView setImage:[p thumbnail]];
        [[cell textLabel]setBackgroundColor:[UIColor clearColor]];
        [[cell textLabel]setText:firstAndLastName];
        [[cell detailTextLabel]setBackgroundColor:[UIColor clearColor]];
        [[cell detailTextLabel]setText:[p phoneNumber]];

        totalNumberOfRows = totalNumberOfRows + 1;
    }
    return cell;
}

    #pragma mark - Action Row Support

-(NSIndexPath *)modelIndexPath: (NSIndexPath *)indexPath
{

    if (self.actionRowIndexPath == nil) {
        return indexPath;

    }

    if ([indexPath row] > [self.actionRowIndexPath row]) {
        return [NSIndexPath indexPathForRow:([indexPath row] - 1) inSection:indexPath.section];

    }
    return indexPath;

}

 - (void)handleDoubleTap:(UITapGestureRecognizer *)recognizer {


    NSLog(@"Double tap");

    CGPoint p = [recognizer locationInView:self.tableView];

    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];


    NSIndexPath *pathToDelete = self.actionRowIndexPath;

    _selectedIndexPath = [self modelIndexPath:_selectedIndexPath];

    //Is the user deselecting current row?
    if (_actionRowIndexPath) {
        [self.tableView deselectRowAtIndexPath:_selectedIndexPath animated:NO];
        self.selectedIndexPath = nil;
        self.actionRowIndexPath = nil;
    } else {
        //Selecting a new row
        self.selectedIndexPath = indexPath;

        self.actionRowIndexPath= [NSIndexPath indexPathForRow:([indexPath row] + 1) inSection:[indexPath section]];
    }

    [self.tableView beginUpdates];
    if (pathToDelete) {
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:pathToDelete] withRowAnimation:UITableViewRowAnimationAutomatic];

    }
    if (self.actionRowIndexPath) {
        [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:self.actionRowIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    }
    [self.tableView endUpdates];  
}
  • 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-14T16:30:42+00:00Added an answer on June 14, 2026 at 4:30 pm

    After you get the IndexPath you need to get the IndexPath.row and IndexPath.section and accordingly you need to add the object into your array at the desired index. For example: if you double tap the 2nd row in the 1st section then you need to add the object at index 4 of the array corresponding to the 1st section and then reload table. The cell would be added to the 3rd index of the 1st section.

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

Sidebar

Related Questions

I have an Android app that I had working a few months ago which
I'm trying to access the Twitter stream which I had working previously while improperly
I had working a java script in my html page.Now i moved the script
I have a problem that I had working in a test but now in
Last night I tried to put together something that I have had working since
Had this working; at one stage. The problem is the following text is now
I had a working Active Admin app working on my local server, but after
I had this working at some point, as I had a question about this
I had started working on GPGPU some days ago and successfully implemented cholesky factorization
I had been working on server side(c#) for a couple of years. But now

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.