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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:13:02+00:00 2026-05-23T17:13:02+00:00

I am showing comments in UItableView and created delete button in Cell..When I delete

  • 0

I am showing comments in UItableView and created delete button in Cell..When I delete any comment It will delete. and I used [Tableview reloadData], but It always delete last cell from table and when I checked the deleted comment next time it is fine.. Why table view always delete last cell.. My code is

- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i",indexPath.row];

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

   if (cell == nil) {
                    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];


       //delete button in uitableview cell ================================

         deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];

         deleteBtn.frame = CGRectMake(270, 10, 20, 20);

          //[deleteBtn setTitle:@"delete" forState:UIControlStateNormal];

          [deleteBtn setImage:[UIImage imageNamed:@"deletefb.png"] forState:UIControlStateNormal];
          deleteBtn.tag = indexPath.row;

          [deleteBtn addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
                    deleteBtn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;

           [cell.contentView addSubview:deleteBtn];

            }

            return cell;

    }  

Delete method is

- (void )delete:(id)sender {


    UIButton *myDeleteButton = (UIButton *)sender ;




    //delete method of comment

    NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:1];

    [variables setObject:@"delete" forKey:@"method"];


    [fbGraph doGraphPost:[NSString stringWithFormat:@"%@",[(Facebook *)[tableArray objectAtIndex:myDeleteButton.tag]postId]] withPostVars:variables];


     //load tableview 
    [self responseMethod];  //method to load comments
    //show alert
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Deleted"
                                                   message:@"" delegate:nil
                                         cancelButtonTitle:@"Ok" otherButtonTitles:nil ];

    [alert show];
    [alert release];







}
  • 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-23T17:13:03+00:00Added an answer on May 23, 2026 at 5:13 pm

    Try moving deleteBtn.tag = indexPath.row; outside of the if (cell == nil) condition.

    In your current setup, when you reuse a cell rather then instantiate a new one the tag will reference the old indexPath.row rather than that of the new one. This may well be why you’re seeing cells deleted other than the one expected.

    if (cell == nil) {
        // Do you other stuff here         
    }
    deleteBtn.tag = indexPath.row;
    return cell;
    

    Also, you don’t seem to grasp the concept of reusing table cells. The identifier should be a constant string applied to all cells, not a dynamic one as you have setup here. For instance

    NSString *identifier = @"someUniqueValue";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to allow comments by anon users but the add comment form, add
In showing a colleague how to use SVN yesterday, we created a test folder
Wordpress is acting crazy when posting comments, showing a 500 Internal Server Error every
I'm at a loss to for a solution to my comments section not showing
Hello I am using facebook graph api..and trying to display comments of each post..But
I have a view that is showing details of my post with comments, it
I have article model with public ICollection<Comment> Comments { get; set; } and comment
I have multiple table in which i'm showing comments. Each table have same elements.
A function like this is showing comments on my website $retrieve = $con->select2(*, `comments`,
I am using following tag for showing comments on jsp, now I want 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.