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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:59:25+00:00 2026-06-07T06:59:25+00:00

I am a beginner of iOS and in the programming tutorials when adding button

  • 0

I am a beginner of iOS and in the programming tutorials when adding button programmatically, target is always set to self, and in that controller where it is being created, an action (IBAction) is written. Or through the interface builder, target is set to File’s Owner.

My question is that in what scenario (an example would be great) that target is not self.

One scenario I can think of is when in a class’s (which is not a ViewController) method a button is created depending on a condition, since that class is not a ViewController, when initializing an object of that class, a reference to the current ViewController would be set and that will be used as target where action is defined for the button if it appears.

  • 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-07T06:59:27+00:00Added an answer on June 7, 2026 at 6:59 am

    You can direct the selector to any target – the reason why ordinarily, self is the target is because it is quite normal to instantiate a UIButton/UIBarButtonItem in code, so a lot of tutorials include the implementation the selector references in the same class.

    You could, for example, make a class that when instantiated in your View Controller is designed to only handle these button invocation actions:

    #import <UIKit/UIKit.h>
    #import "OtherObject.h"
    
    @interface SomeViewController : UIViewController
    
    @property (strong, nonatomic) OtherObject *other;
    
    @end
    
    @implementation SomeViewController
    
    @synthesize other;
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIButton *someButton = [[UIButton alloc] initWithFrame:CGRectZero];
        [someButton addTarget:other action:@selector(someMethodInOther) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:someButton];
    
        UIButton *anotherButton = [[UIButton alloc] initWithFrame:CGRectZero];
        [anotherButton addTarget:other action:@selector(anotherMethodInOther) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:anotherButton];
    }
    
    @end
    

    IBAction lets you tell Interface Builder that the method implementation can be connected through your xib/storyboard.

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

Sidebar

Related Questions

as I am following the second of Apple's beginner-tutorials Your second iOS App, it
Beginner programmer here....hope it makes sense :) I have created a console app that
iOS beginner here. I am implementing SSO in my iOS app. I've created a
iOS beginner here. I have the following code: [facebook authorize:nil delegate:self]; NSString *string1=[facebook accessToken];
How does a beginner go about practicing introspection in Cocoa programming (specifically iOS)? In
Beginner iOS dev here. I have a problem in my array. Im making an
Possible Duplicate: multiple UIAlertView issue I`am beginner ios developer. And I faced with the
I am a beginner to the iOS app development and working on a sample
I'm a beginner to the iOS development, and I'm trying to display an image
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later

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.