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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:50:54+00:00 2026-05-14T18:50:54+00:00

I have a couple UIViewControllers that I am trying to access an array inside

  • 0

I have a couple UIViewControllers that I am trying to access an array inside my AppDelegate. When I use an IBAction UIButton and in that method I access my AppDelegate my program dies silently. Nothing in output or the debugger, it just stops. If I run it several times I can see that it is failing to access the array properly.

To investigate this problem I created a very basic app.

In my AppDelegate.h I declared and set properties for the array

#import <UIKit/UIKit.h>
@class MyViewController;
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    MyViewController *viewController;
    NSArray *images;
}
@property (nonatomic, retain) NSArray *images;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MyViewController *viewController;`

In the AppDelegate.m I synthesised and initialized the NSArray (Also made sure the images were added to the Resources folder).

@synthesize images;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    images = [NSArray arrayWithObjects:
        [[NSBundle mainBundle] pathForResource:@"bamboo_nw" ofType:@"jpg"],
        .....
        nil];
    NSLog(@"init images size:%i",[images count]); 
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    return YES;
}

In my UIViewController.h I added class, imported header file, declared, and set properties for my AppDelegate pointer.

#import <UIKit/UIKit.h>
#import "MyAppDelegate.h"
@class MyAppDelegate;
@interface MyViewController : UIViewController {

MyAppDelegate *mainDelegate;
IBOutlet UIButton mybutton;
}
@property (nonatomic, retain) MyAppDelegate
mainDelegate;
@property (nonatomic, retain) UIButton *mybutton;
-(IBAction) doSomething;`

In my UIViewController.m I synthesize and assign my AppDelegate. I set up an IBAction that will log the same count of the NSArray from the AppDelegate.

#import "MyViewController.h"
#import "MyAppDelegate.h"
@implementation MyViewController
@synthesize mybutton;
- (void)viewDidLoad {
    mainDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSLog(@"vdl images size:%i",[mainDelegate.images count]);
    [super viewDidLoad];
}
-(IBAction) doSomething {

NSLog(@”ds images size:%i”,[mainDelegate.images count]);
}

I print the size of the NSArray in the AppDelegate when I create it, in the ViewController when I first assign my AppDelegate pointer, and then as a result of my IBAction.

I find that everytime I hit the button the program dies. On the third time I hit the button, I saw that it ran my IBAction but printed my array size as 1 instead of 8. Am I missing something? Also, why don’t I get stack traces or anything, the debugger just dies silently?

Thanks in advance for any help!

Debugger Console output for 3 runs:

[Session started at 2010-05-10 06:21:32 -0700.]
2010-05-10 06:21:44.865 My[59695:207] init images size:8
2010-05-10 06:21:47.246 My[59695:207] vdl images size:8

[Session started at 2010-05-10 06:22:15 -0700.]
2010-05-10 06:22:18.920 My[59704:207] init images size:8
2010-05-10 06:22:19.043 My[59704:207] vdl images size:8

[Session started at 2010-05-10 06:22:23 -0700.]
2010-05-10 06:22:25.966 My[59707:207] init images size:8
2010-05-10 06:22:26.017 My[59707:207] vdl images size:8
2010-05-10 06:22:27.814 My[59707:207] ds images size:1
  • 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-14T18:50:54+00:00Added an answer on May 14, 2026 at 6:50 pm

    You need to use self.images as your lvalue in application:DidFinishLaunchingWithOptions:, to wit:

    @synthesize images;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions(NSDictionary *)launchOptions {    
        self.images = [NSArray arrayWithObjects:
            [[NSBundle mainBundle] pathForResource:@"bamboo_nw" ofType:@"jpg"],
            .....
            nil];
        NSLog(@"init images size:%i",[images count]); 
        [window addSubview:viewController.view];
        [window makeKeyAndVisible];
        return YES;
    }
    

    When you use the ivar images without the self, you are giving up the goodness of the automatic retention that you set up when you created the @property.

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

Sidebar

Related Questions

ok I have couple of .NET classes that I want to use in VBA.
I have couple of dozen pieces of data that I need to save and
I have couple resource DLLs that I currently load when application starts using following
We have couple different web-apps that share the same db link. The hibernate layer
I have a couple of UITableViewController classes and I just noticed that these methods
I have a ViewController that has a couple of IBOutlet properties defined for UITextView.
I have an uitabbarcontroller which contains a couple uiViewControllers. When i show one of
I have an app which has a UINavigationController, which has a couple of UIViewControllers.
I have couple of tables, where I cannot use hibernate mappings to define associations
In my app I have couple activities. How to setup that every time user

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.