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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:09:07+00:00 2026-06-03T13:09:07+00:00

I would like the view controller to be able to access dog in the

  • 0

I would like the view controller to be able to access dog in the app delegate.

I would like the app delegate to be able to access mouse in the view controller.


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    int mouse;  // <----------------
}
@end

- (void)viewDidLoad
{
    [super viewDidLoad];

    mouse = 12;  // <-------------------

    NSLog(@"viewDidLoad %d", dog); // <---------------
}

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    int dog;  // <---------------
}
@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;

@end

- (void)applicationWillResignActive:(UIApplication *)application
{
    NSLog(@"applicationWillResignActive %d", mouse); // <--------------
}

 - (void)applicationDidBecomeActive:(UIApplication *)application
{
    dog = 77; // <---------------------

    NSLog(@"applicationDidBecomeActive");
}
  • 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-03T13:09:09+00:00Added an answer on June 3, 2026 at 1:09 pm

    Part 1:
    In the ViewController.h:

    -(int)mouse;  //add this before the @end
    

    In the ViewController.m, add this method:

    -(int)mouse
    {
        return mouse;
    }
    

    To access mouse from AppDelegate, use self.viewController.mouse
    For example;

    NSLog(@"ViewController mouse: %i", self.viewController.mouse);
    

    Part2:

    In the AppDelegate.h:

    -(int)dog;  //add this before the @end
    

    In the AppDelegate.m, add this method:

    -(int)dog
    {
        return dog;
    }
    

    In the ViewController.m:

    #import "AppDelegate.h"
    

    To access dog from ViewController, use this:

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    NSLog(@"dog from AppDelegate: %i", [appDelegate dog]);  //etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a modal view controller activated in my app, and I would like
I would like to be able to add a score, in a different view
I would like to know which ViewController is currently the active one. in other
I have a ViewController that has its own NIB. I would like to embed
For example I have a ViewController named firstViewController. Then I would like to call
I currently have NSXMLParser working in my viewcontroller. I would like to create a
I would like to implement a view similar to the detail view of Apple's
I would like to create a view where this subview will be in repeated
I would like to get the view that is the first responder, currently I
I would like to animate a view along a path. While it moves from

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.