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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:33:11+00:00 2026-06-12T09:33:11+00:00

I have a view controller which contains nested UIView . I would like to

  • 0

I have a view controller which contains nested UIView. I would like to add a tap listener for each subview I’m adding. But I caught a SIGABRT error when I tap the subview.

Here is my code:

- (void) viewDidLoad {
    [super viewDidLoad];

    //set container
    UIView *container = [[UIView alloc] initWithFrame:CGRectMake(5, 5, 320, 420)];
    container.backgroundColor = [UIColor blueColor];

    //create new subview within container. I call it "card"
    for (int i=0; i<5; i++)
    {
        //create card
        UIView *card = [[UIView alloc] initWithFrame:CGRectMake(10, 35 + (65 * i), 300, 45)];
        card.backgroundColor = [UIColor greenColor];

        //set tap event with action selector = cardRowTapped
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cardRowTapped)];
        [card addGestureRecognizer:tap];

        //add subview
        [container addSubview:card];
    }

    //add subview to self
    [self.view addSubview:container];

}

and here is my tap handler code

- (void) cardRowTapped:(UITapGestureRecognizer *)gr {
    NSLog( @"hello");
}

Console output:

2012-10-03 13:23:37.173 MyProject[5167:707] -[MyViewController
cardRowTapped]: unrecognized selector sent to instance 0x2cd810

2012-10-03 13:23:37.179 MyProject[5167:707] * Terminating app due to
uncaught exception ‘NSInvalidArgumentException’, reason:
‘-[MyViewController cardRowTapped]: unrecognized selector sent to
instance 0x2cd810’

* First throw call stack: (0x314b888f 0x377f6259 0x314bba9b 0x314ba915 0x31415650 0x30c45637 0x30bd5d65 0x30e06479 0x30b51f55
0x30b50aa3 0x30b5d7e9 0x30b5d627 0x30b5d1f5 0x30b43695 0x30b42f3b
0x3348922b 0x3148c523 0x3148c4c5 0x3148b313 0x3140e4a5 0x3140e36d
0x33488439 0x30b71cd5 0x76e8d 0x76e28) terminate called throwing an
exception(lldb)

Any idea why this is happening?

  • 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-12T09:33:12+00:00Added an answer on June 12, 2026 at 9:33 am

    your method requires a member variable which is passed by the gesture, so change the tap gesture method like below,

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cardRowTapped:)];
    

    and check out it should work, one more thing if you are not using ARC, then release the objects after their usage.

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

Sidebar

Related Questions

I have 2 view controller pages.Add Reminder page which contains save button as right
I am using a view Controller which have contains tabbarcontroller(4 tabs). each tabbar have
i have view controller which contains a button which show the image library ,if
So, i have a view controller which contains just a scroll view. In viewDidLoad,
I have a xib with a view which contains two views which each contain
I have a view controller which contains a scroll view. Inside the scroll view
I have a view controller which contains a UISearchBar @interface TradeFindHeaderViewController_iPhone : UIViewController {
I have a root view controller which contains an outlet for my login view
I have a view controller MainVC which contains a view where I want to
I have a UIScrollView which contains a view controller which contains a couple of

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.