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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:05:19+00:00 2026-06-11T11:05:19+00:00

In my ipad app I need to drag and drop a UIButton to insert

  • 0

In my ipad app I need to drag and drop a UIButton to insert a cell. I managed to drag a button and inserting a cell by touchupinside event. It works with following code –

//button1 is initially placed in a view called scrollview
[button1 addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];

[button1 removeTarget:self action:@selector(insertcell) forControlEvents:UIControlEventTouchUpInside];

CGPoint pointfordeterminingrow;

- (IBAction) imageMoved:(UIButton *) sender withEvent:(UIEvent *) event {

    CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
    UIControl *control = sender;
    control.center = point;

    pointfordeterminingrow=point;   // point where the button is hovering now

    if ([sender state] == UIGestureRecognizerStateBegan) {

        [self.view addSubview:sender];

    }

    if ([sender state] == UIGestureRecognizerStateChanged) {

        [scrollview addSubview:sender];

    }

    if ([sender state] == UIGestureRecognizerStateEnded) {

        [scrollview addSubview:sender];

    }

}

- (int)rowAtPoint:(CGPoint)point {

    NSIndexPath* newIndexPath = [MainTableView indexPathForRowAtPoint:point];
    return newIndexPath == nil ? [items count] : newIndexPath.row;

     //items is a mutable array has the content of each cell
}

-(void)insertcell {

    int row = [self rowAtPoint:pointfordeterminingrow];

    NSIndexPath* newIndexPath = [NSIndexPath indexPathForRow:row inSection:0];

    [self insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath                 indexPathForRow:newIndexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
}

These codes insert a cell at the indexpath above which the button is dropped //touchuped method gets called.

MY PROBLEM IS:

“newIndexPath” which I get is a number (row in tableview) on which the button is dropped. This “insertcell” method works fine in situation when the tableview is not scrolled,

When the TableView is scrolled “rowAtPoint” returns a number which is the row at indexpath witch is VISIBLE as of now.

In Other Words, if the button is dropped above indexpath 58 and if 50 cells are hidden above (by scrolling) i get the number 8,(not 58)

So when the button is dropped at indexpath 58 a cell is inserted AT INDEXPATH 8.

I need suggestions to get the EXACT indexpath in a tableview at a point. provided the “point” is the CGPoint in self.view.

  • 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-11T11:05:19+00:00Added an answer on June 11, 2026 at 11:05 am

    Try this:

    int row = [self rowAtPoint:pointfordeterminingrow];
    
    [myTableView visibleCells];  // call this first to avoid possible iOS bug in next statement
    NSArray *visIndexPaths = [myTableView indexPathsForVisibleRows]; 
    
    
    NSIndexPath* newIndexPath = [visIndexPaths objectAtIndex:row];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert a web app into ipad app. Stressing on style and
I need to add iCloud to my MonoTouch iPhone/iPad app, allowing the User to
I need to build a backend for an iPad app done in Objective C.
I need to determine what iPad version my app is running on before setting
I am writing an app for the iPhone and iPad and I need it
I've got an iPad app that I absolutely need to have in just landscape,
I need to draw a Gantt-Chart within my iPad App. Are there any frameworks
I have the need for some time based effects in the iPad app I
In my iPad app I need to display cover-Images of publications. The user can
I'm need to create an ipad app that has access to a relational database

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.