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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:39:09+00:00 2026-05-28T13:39:09+00:00

I made a button above a pickerView to dismiss it. and I think I

  • 0

I made a button above a pickerView to dismiss it.
and I think I made it,
here the the code that initiates the pickerView as well as its dismiss button.

    UIPickerView *tempPickerView = [[[UIPickerView alloc] initWithFrame:
        CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
    tempPickerView.showsSelectionIndicator = YES;
    tempPickerView.delegate = self;
    tempPickerView.dataSource = self;
    UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, -32, 52, 32)];
    [pickerButton setBackgroundImage:[UIImage imageNamed:@"week.png"] 
         forState:UIControlStateNormal];
    [pickerButton addTarget:self action:@selector(hidePicker) 
         forControlEvents:UIControlEventTouchUpInside];
    [tempPickerView addSubview:pickerButton];
    [tempPickerView bringSubviewToFront:pickerButton];
    [pickerButton release];

    [self.view addSubview:tempPickerView];
    return tempPickerView;

and it looks like this:

enter image description here

that button is at the upper left cornor of the pickerView, forget about the “week”, it is just a temporary name.

Problem is, I can’t touch this button, everytime I tried to touch it, I just directly touched things behind it such as the talbeViewCell.

Is is because I added the button outside of the pickerView’s frame?

I mean the coordinate of the button’s origin is (0, -32),

so that it would be displayed above the pickerView, is there any problems with the coordinate?

Can anyone tell how to fix this problem?

Thanks a lot and a lot!!!

  • 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-28T13:39:10+00:00Added an answer on May 28, 2026 at 1:39 pm

    The problem is that you have placed the button outside the bounds of its parent view. iOS now does this (simplified, not 100% correct but you get the deal):

    • It notices a touch occurred. It calculates the coordinates of that touch.
    • It then tries to find out which view was touched. To do so, it calls the hitTest:withEvent: method on the UIWindow object of your app.
    • That in turn calls hitTest:withEvent: on each of its children, and these each call hitTest:withEvent: on their children if necessary.
    • When a view’s hitTest:withEvent: is called, it first looks whether the coordinate is within its own bounds (IIRC). If it isn’t, it returns nil. Otherwise it calls hitTest:withEvent: on its children.

    The hitTest:withEvent: documentation explicitly says:

    Points that lie outside the receiver’s bounds are never reported as hits, even if they actually lie within one of the receiver’s subviews.

    The problem now is that your button is outside of its parent view. So hitTest:withEvent: determines that the touch coordinate is not inside the bounds of the picker view and never bothers to ask its child (the button) whether it might be hit.

    You could subclass the picker and override the hitTest:withEvent: method to “fix” this, but the real fix is to move the button so its a sibling of the picker, not a child.

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

Sidebar

Related Questions

I made a button component in Delphi, and I write a code with error
I have a button as made for you to see here . Looks fine,right?
I made an extension for IE9 that adds a toolbar button. The registration looks
I have made an app OB Nyt that works well on Froyo and below
I've made a button background from shapes and is looking quite good for my
I made a login button and want to check if the user logged in
I have AntiVirus , and I want to made an update button to update
I have an anchor tag <a class=next>next</a> made into a button. Sometimes, this tag
I made a camera layout where two buttons existed.A click button and a share
I have made a custom suface button according this example: <Button> <Button.Template> <ControlTemplate TargetType=Button>

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.