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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:18:32+00:00 2026-05-29T09:18:32+00:00

My appDelegate, in the method didFinishLaunchingWithOptions I load my view controller then create a

  • 0

My appDelegate, in the method didFinishLaunchingWithOptions I load my view controller then create a singleton:

UIViewController *MainWinVC = [[p3VC alloc] init];
[[self window] setRootViewController:MainWinVC];
ansButSingleton *ansButs = [[ansButSingleton alloc] init]; 

ansButSingleton.h looks like this:

#import <Foundation/Foundation.h>

@interface ansButSingleton : NSObject {

    // View objects:

    UIButton *Ans1;
    UIButton *Ans2;
    UIButton *Ans3;
    UIButton *Ans4;
    UIButton *Ans5;
    UIButton *Ans6;
    UIButton *Ans7;
    UIButton *Ans8;

    // Other objects:

    NSArray *ansButs;

}

@property (strong) UIButton *Ans1, *Ans2, *Ans3, *Ans4, *Ans5, *Ans6, *Ans7, *Ans8;
@property (strong) NSArray *ansButs;

+ (ansButSingleton *) ansButsName;  // Declare class method
@end

and ansButSingleton.m like this:

#import "ansButSingleton.h"

@implementation ansButSingleton

static ansButSingleton *ansButsName;

@synthesize Ans1, Ans2, Ans3, Ans4, Ans5, Ans6, Ans7, Ans8;
@synthesize ansButs;

//////////////////// instantiate ////////////////////

+ (ansButSingleton *) ansButsName { // class method

    @synchronized(self)
    {
        if (!ansButsName)
            ansButsName = [[ansButSingleton alloc] init];        
        return ansButsName;
    }
}

//////////////////// initialize ////////////////////

- (id)init { // class instance method

    NSLog(@"Initializing answer buttons");

    if (ansButsName) {
        return ansButsName;
    }

    self = [super init];

    if(self) {

        // First initialze the individual buttons

        self.Ans1 = [[UIButton alloc] init];
        [Ans1 setTitle:@"" forState:UIControlStateNormal];
        self.Ans2 = [[UIButton alloc] init];
        [Ans2 setTitle:@"" forState:UIControlStateNormal];
        self.Ans3 = [[UIButton alloc] init];
        [Ans3 setTitle:@"" forState:UIControlStateNormal];
        self.Ans4 = [[UIButton alloc] init];
        [Ans4 setTitle:@"" forState:UIControlStateNormal];
        self.Ans5 = [[UIButton alloc] init];
        [Ans5 setTitle:@"" forState:UIControlStateNormal];
        self.Ans6 = [[UIButton alloc] init];
        [Ans6 setTitle:@"" forState:UIControlStateNormal];
        self.Ans7 = [[UIButton alloc] init];
        [Ans7 setTitle:@"" forState:UIControlStateNormal];
        self.Ans8 = [[UIButton alloc] init];
        [Ans8 setTitle:@"" forState:UIControlStateNormal];

        // Make an array containing the objects: this is the objective-C way!

        self.ansButs = [[NSArray alloc] initWithObjects: Ans1, Ans2, Ans3, Ans4, Ans5, Ans6, Ans7, Ans8, nil];
    }

    NSLog(@"Done initializing answer buttons");

    return self;
}
@end

This builds and runs fine (it doesn’t do much yet). The buttons are visible due to the successful loading of the nib. However, they are not active since I haven’t connected them to the code (no IBActions).

Question: How do I connect buttons created this way to the buttons in the nib? If these were simple buttons (not an array of buttons) I would create a method and use IBAction as part of that method declaration. But this case seems a bit different. Or maybe not. If these were labels (which I also need to do later), my reading leads me to believe IBOutletCollection might work, but there is no IBActionCollection that I can see. Expert guidance needed! Thanks.

EDIT … working with Rob to implement his ideas. My viewLoad method was copied and pasted from yours, but maybe there was something in it I needed to change?

#pragma mark - View lifecycle

 - (void)loadView {
 NSDictionary *externals = [NSDictionary dictionaryWithObject:[AnswerButtons answerButtons]
 forKey:@"answerButtons"];
 NSDictionary *nibOptions = [NSDictionary dictionaryWithObject:externals
 forKey:UINibExternalObjects];
 [self.nibBundle loadNibNamed:self.nibName owner:self options:nibOptions];
 [[AnswerButtons answerButtons] buttonsDidLoad];
 }
  • 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-29T09:18:33+00:00Added an answer on May 29, 2026 at 9:18 am

    There are a number of ways you could do this. I’d do it by hooking up the singleton’s connections in the nib. Here’s how.

    First, let’s fix up the singleton class to match iOS programming conventions and provide the support for wiring up the button connections in the nib:

    AnswerButtons.h

    #import <Foundation/Foundation.h>
    
    @interface AnswerButtons : NSObject
    
    @property (strong, nonatomic) IBOutlet UIButton *button1, *button2, *button3, *button4, *button5, *button6, *button7, *button8;
    @property (strong, nonatomic, readonly) NSArray *buttons;
    
    + (AnswerButtons *)answerButtons;
    
    - (void)buttonsDidLoad;
    
    @end
    

    AnswerButtons.m

    #import "AnswerButtons.h"
    
    @implementation AnswerButtons
    
    @synthesize button1 = _button1;
    @synthesize button2 = _button2;
    @synthesize button3 = _button3;
    @synthesize button4 = _button4;
    @synthesize button5 = _button5;
    @synthesize button6 = _button6;
    @synthesize button7 = _button7;
    @synthesize button8 = _button8;
    
    @synthesize buttons = _buttons;
    
    + (AnswerButtons *)answerButtons {
        static AnswerButtons *singleton;
        static dispatch_once_t once;
        dispatch_once(&once, ^{
            singleton = [[AnswerButtons alloc] init];
        });
        return singleton;
    }
    
    - (void)buttonsDidLoad {
        _buttons = [[NSArray alloc] initWithObjects:_button1, _button2, _button3, _button4, _button5, _button6, _button7, _button8, nil];
    }
    
    @end
    

    Note that we create the singleton in the class method the first time the singleton is requested. Don’t do it in application:didFinishLaunchingWithOptions:.

    Next, let’s hook up the buttons in the nib:

    1. Open the nib for the p3VC class. (You should consider changing this name to start with a capital letter and spell out ViewController or just Controller.)
    2. Drag an “External Object” from the Object Library into the nib.
    3. In the Identity Inspector, set the External Object’s custom class to AnswerButtons.
    4. In the Attributes Inspector, set its External Object Identifier to answerButtons.
    5. Control-drag from the Answer Buttons object to each of the eight buttons, connecting the button to the appropriate outlet.

    Finally, we need to provide the AnswerButtons singleton to the nib loader when we load the nib. Edit p3VC.m and give it a loadView method:

    p3VC.m

    - (void)loadView {
        NSDictionary *externals = [NSDictionary dictionaryWithObject:[AnswerButtons answerButtons]
            forKey:@"answerButtons"];
        NSDictionary *nibOptions = [NSDictionary dictionaryWithObject:externals
            forKey:UINibExternalObjects];
        [self.nibBundle loadNibNamed:self.nibName owner:self options:nibOptions];
        [[AnswerButtons answerButtons] buttonsDidLoad];
    }
    

    With this approach, you can also create IBAction methods in the AnswerButtons class and use the nib to connect the buttons to those actions.

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

Sidebar

Related Questions

I am trying to load my UIViewController and corresponding UIView programmatically in the AppDelegate
I'm trying to call a method in the view controller from the app delegate,
I am trying to add a View Controller to the Appdelegate Class. My code
I added this code in my AppDelegate in didFinishLaunchingWithOptions method: [[UINavigationBar appearance]setBackgroundColor:[UIColor colorWithRed:221/256.0 green:36/256.0
In my AppDelegate.m, in the application: didFinishLaunchingWithOptions: method, I put the following line: NSManagedObjectContext
I have an Obj-C method similar to this: -(void)getUserDefaults:(BOOL *)refreshDefaults { PostAppDelegate *appDelegate =
Hi i have a strange issue after adding my UIViewController.view to my Application Window.
I have a question regarding view controller navigations in Three20. I have a TTTableView
I am trying to integrate AdWhirl into my iPhone app using an AppDelegate singleton
I created a navigation controller based app. The view that opens up below the

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.