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

  • Home
  • SEARCH
  • 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 7895717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:42:39+00:00 2026-06-03T07:42:39+00:00

I have UITableView that contains many cell. User can expand cell to see more

  • 0

I have UITableView that contains many cell. User can expand cell to see more content in this cell by push the expand button in this cell (only 1 cell can expand at time):

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(selectedRowIndex == indexPath.row) return 205;
    else return 60;
}

In the storyboard, I drag UILongPressGesture into cell button and named it longPress (cell is custom, it has 2 buttons in it, 1 need to recognize LongPressGesture, the other expand cell height):

@property (retain, nonatomic) IBOutlet UILongPressGestureRecognizer *longPress;

And in the viewDidLoad:

- (void)viewDidLoad
{      
    [longPress addTarget:self action:@selector(handleLongPress:)];
}

It’s work perfectly, however when I use following code to recognize cell indexPath, it’s wrong when one cell is expanded:

- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {         
    // Get index path
    slidePickerPoint = [sender locationInView:self.tableView];
    NSIndexPath *indexPath= [self.tableView indexPathForRowAtPoint:slidePickerPoint]; 
    // It's wrong when 1 cell is expand and the cell's button I hold is below the expand button
}

Can anyone please show me how to get correct indexPath when there’re different cell height?
Thank 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-06-03T07:42:40+00:00Added an answer on June 3, 2026 at 7:42 am

    One way to do it would be to add a UILongPressGestureRecognizer to each UITableViewCell (that all use the same selector), then when the selector is called you can get the cell via sender.view. Perhaps not the most memory efficient, but if the single gesture recognizer won’t return the right row in certain situations, this way should work.

    Something like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        ...
    
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
      initWithTarget:self action:@selector(handleLongPress:)];
        [longPress setMinimumPressDuration:2.0];
        [cell addGestureRecognizer:longPress];
        [longPress release];
    
        return cell;
    }
    

    then

    - (void)handleLongPress:(UILongPressGestureRecognizer*)sender {  
        UITableViewCell *selectedCell = sender.view;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView that contains a UITextField in each cell. I can't seem
I have a popover that contains a UITableView. This UITableView has a cell with
I have a UITableView with many rows that push a DetailViewController depending on the
I have a UIViewController that contains a UITableView. I'm trying to fill this table
I have a UITableView with many rows, each row contains a UIWebView. The content
I have a problem with data in UITableView. I have UIViewController, that contains UITableView
I have a UITableView that displays single large images in each cell. The names
I have a uitableview that loads fairly large images in each cell and the
I have an UITableView that contains 2 buttons for each UITableviewCell. How to hide
I have a grouped UITableView that contains several cells (just standard UITableViewCell s), all

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.