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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:36:46+00:00 2026-06-09T19:36:46+00:00

i have 2 uibutton and 1 label and longpressgesture is bounded to these control.

  • 0

i have 2 uibutton and 1 label and longpressgesture is bounded to these control. when longpress is taken place on any control then how to get the object on which longpress is taken place below is the code that i have written.

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[btn addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
//[self.view addSubview:btn];
btn.userInteractionEnabled = YES;

// add it
[self.view addSubview:btn];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
                                           initWithTarget:self 
                                           action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
[btn addGestureRecognizer:longPress];

below is function that is called on longpress

-(void)handleLongPress:(id)sender{
 }

if i printing description of sender then i get

 <UILongPressGestureRecognizer: 0x6aa4480; state = Began; view = <UIRoundedRectButton 0x6aa9570>; target= <(action=handleLongPress:, target=<ViewController 0x6a8cc60>)>>

from it how can i get the refrence of object on whcih longpress event takes place
i mean how do i know whether i preessed UiLabel or Uibutton?

  • 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-09T19:36:48+00:00Added an answer on June 9, 2026 at 7:36 pm

    Just check the UIGestureRecognizer’s (the parent class) view property:

    @property(nonatomic, readonly) UIView *view

    The view the gesture recognizer is attached to. (read-only)

    @property(nonatomic, readonly) UIView *view
    Discussion
    You attach (or add) a gesture recognizer to a UIView object using the addGestureRecognizer: method.

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

Sidebar

Related Questions

I have a UIButton on which I am putting a text label. I want
I have a UIButton which fires a target action causing one view to transition
I have subview which it initiated by touch on the UIbutton in the main
I have a custom UIButton that has the label Name. When the user clicks
I have a UIButton that I create in my sub class ViewController, and add
I have a UIButton that should have 2 statuses - Play and Pause; i.e.
I have a UIbutton title that I set with [[buttons objectAtIndex:selectedButtonTag] setTitle:file forState:UIControlStateNormal]; This
I have a UIButton called as UploadButton . I am using the following lines
I have a UIButton in a UITableView cell, in a UITableView. The result is
I have a UIButton, and I'd like to update its title, but I'd rather

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.