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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:27:24+00:00 2026-05-26T07:27:24+00:00

I have a UIViewController with a UIView as a subview. I’d like the UIViewController

  • 0

I have a UIViewController with a UIView as a subview. I’d like the UIViewController to be notified of (or listen for) certain actions in the UIView. What’s the standard way of doing this?

  • 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-26T07:27:24+00:00Added an answer on May 26, 2026 at 7:27 am

    If you just want to have an action handler:

    - (void)viewDidLoad {
        [super viewDidLoad];
        // ......
        UIButton *myButton = [[UIButton alloc] init]; // or initWithSOMETHING
        [myButton addTarget:self action:@selector(someMethod:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:myButton];
        [myButton release];
        // ......
    }
    
    - (void)someMethod:(id)sender {
        if (![sender isKindOfClass:[UIButton class]]) return;
        // Do something about the action here...
    }
    

    For more info, see the UIControl Documentation:

    Preparing and Sending Action Messages

    – sendAction:to:forEvent:
    – sendActionsForControlEvents:
    – addTarget:action:forControlEvents:
    – removeTarget:action:forControlEvents:
    – actionsForTarget:forControlEvent:
    – allTargets
    – allControlEvents
    

    Or, if your talking about a view controller calling a parent view controller, you could use the presentingViewController property of a UIViewController to access the “parent” view controller:

    UIViewController *parentVC = [self presentingViewController];
    [parentVC setSomething:self.withSomething];
    

    presentingViewController – The view controller that presented this view controller. (read-only)

    @property(nonatomic, readonly) UIViewController
    *presentingViewController

    Discussion
    The default implementation of this property walks up the view
    hierarchy, starting from this view controller. The first view
    controller it finds that received the
    presentViewController:animated:completion: method, or that has its
    definesPresentationContext property set to YES is returned as the
    value of the property. It keeps walking up the hierarchy until it
    finds a value to return or it gets to the root view controller.


    Or the superview property of a UIView:

    [self.view.superview doSomething];
    

    superview – The receiver’s superview, or nil if it has none. (read-only)
    @property(nonatomic, readonly) UIView *superview

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

Sidebar

Related Questions

I have a custom UIViewController, which is the only subView of UIView. The UIViewController
I have a UIViewController ( AbcViewController ) with NavigationController . AbcViewController uses UIView (
I have a UINavigationController containing an UIViewController initialized with a UIView. The UINavigationController also
I have a pointer to a UIView . How do I access its UIViewController
I have two NIB's ParentViewController.xib ChildViewController.xib ParentViewController.xib contains a UIView and a UIViewController. ChildViewController.xib
I have a UIViewController , it's a view ( UIView ) containing two elements
I have a UIViewController with a UIView in interface builder. I can not for
I have a UIViewController that has both a UITable and a UIView on it.
i have added a UIViewController's view and a button to scrollview as subview...now how
I have a UIViewController subclass to control a UIView that I want to add

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.