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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:59:36+00:00 2026-06-14T05:59:36+00:00

I want to change properties of another object, when a method is called in

  • 0

I want to change properties of another object, when a method is called in another class.

The code to change the properties of this object sits in a method of the first class, and works when calling it from it’s own class, but when called from the other class the object in the method returns nil.

Here is the code:

ViewController.h

@interface ViewController : UIViewController {

    UIView *menuView; //the object

}

@property (nonatomic, retain) IBOutlet UIView *menuView;

-(void)closeMenu; //the method

@end

ViewController.m

@implementation ViewController

@synthesize menuView;

-(void)closeMenu{

    [menuView setFrame:CGRectMake(menuView.frame.origin.x, -menuView.frame.size.height, menuView.frame.size.width, menuView.frame.size.height)];

    NSLog(@"%f", menuView.frame.size.height); //returns height when method is called from it's own class. But returns 0 (nil) when called from the other class.

}

SDNestedTableViewController.h (nothing too important, but might help?)

@interface SDMenuViewController : SDNestedTableViewController{


}

SDNestedTableViewController.m

#import "SDMenuViewController.h"
#import "ViewController.h"

- (void) item:(SDGroupCell *)item subItemDidChange:(SDSelectableCell *)subItem
{

    ViewController *firstViewController = [[[ViewController alloc] init] autorelease];

    SelectableCellState state = subItem.selectableCellState;
    NSIndexPath *indexPath = [item.subTable indexPathForCell:subItem];
    switch (state) {
        case Checked:
            NSLog(@"Changed Sub Item at indexPath:%@ to state \"Checked\"", indexPath);


            [firstViewController closeMenu]; //called from other class


            break;
        case Unchecked:
            NSLog(@"Changed Sub Item at indexPath:%@ to state \"Unchecked\"", indexPath);
            break;
        default:
            break;
    }
}
  • 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-14T05:59:37+00:00Added an answer on June 14, 2026 at 5:59 am

    EDIT 2:

    Well, you shipped your code over to me, so now I can no longer say that I don’t have enough information to solve your problem.

    Let’s see.

    Now I see that your ViewController is the rootViewController of your app, like so:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    

    Good, now how does the ViewController relate to your SDNestedTableViewController?

    You have this in your ViewController’s viewDidLoad:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        SDMenuViewController *mvc = [[[SDMenuViewController alloc] initWithNibName:@"SDNestedTableView" bundle:nil] autorelease];
        [self addChildViewController:mvc];
        [mvc didMoveToParentViewController:self];
        [menuView addSubview:mvc.view];
    
        // Some other stuff with gesture recognizers I'm omitting...
    
        [self openMenu];
    
    }
    

    Alright, so it looks like SDMenuViewController is the child of ViewController. Now, you have a method in SDMenuViewController called item:subItemDidChange:

    - (void) item:(SDGroupCell *)item subItemDidChange:(SDSelectableCell *)subItem
    {
    
        ViewController *firstViewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    
        SelectableCellState state = subItem.selectableCellState;
        NSIndexPath *indexPath = [item.subTable indexPathForCell:subItem];
        switch (state) {
            case Checked:
                NSLog(@"Changed Sub Item at indexPath:%@ to state \"Checked\"", indexPath);
    
                //close the menuView
    
                [firstViewController closeMenu];
    
                break;
            case Unchecked:
                NSLog(@"Changed Sub Item at indexPath:%@ to state \"Unchecked\"", indexPath);
                break;
            default:
                break;
        }
    }
    

    So, you want the reference back to the existing ViewController object, right? Because right there you’re making another one. So, you can do this:

    ViewController *firstViewController = self.parentViewController;
    

    That gets you a reference to SDMenuViewController’s parent, which is the instance of ViewController. This property is set when you do your addChildViewController: call.


    Okay, this is confusing though:

    In your post, you say that your item:subItemDidChange: method is in SDNestedTableViewController, but in the code you sent me it’s in the SDMenuViewController.

    In the SDNestedTableViewController, I found this method:

    - (void) mainItem:(SDGroupCell *)item subItemDidChange: (SDSelectableCell *)subItem forTap:(BOOL)tapped
    {
        if(delegate != nil && [delegate respondsToSelector:@selector(item:subItemDidChange:)] )
        {
            [delegate performSelector:@selector(item:subItemDidChange:) withObject:item withObject:subItem];
        }
    }
    

    So it looks like you’re not using the same code as in the original post, but close enough, whatever.


    Now, if you want to get a reference to the ViewController instance from anywhere in the app, not just your SDMenuViewController (which happens to be the child of the ViewController instance) you should use @Mathew Varghese’s answer.

    Here’s a restatement of this method:

    1. Add the line + (AppDelegate *)instance; to your AppDelegate.h file.
    2. Add the following method to your AppDelegate.m file.

    Like so:

    + (AppDelegate *)instance
    {
        AppDelegate *dg = [UIApplication sharedApplication].delegate;
        return dg;
    }
    

    Then, in whatever object you want that reference, you #import AppDelegate.h and say ViewController *vc = AppDelegate.instance.firstViewController;

    Anyway, it’s just another way of saying what Mathew mentioned earlier.

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

Sidebar

Related Questions

I want to change some properties of a LINQ query result object without creating
I want to create a method that allows me to change arbitrary properties of
What I want change the properties(e.g. background) of a context menu in a datatemplate
I want change following javascript code to jquery code, How is it? With done
i have many div's with the same background image and i want change this
I want to change a number to a string like this: var i =
I have an object where I maintain a relationship to another object: public class
This is a spin off from another question I posted a few days ago
in my current project I'm using code first approach. I have a type called
I have an object: var long_object_name = { 'init':function(){ this.properties.the_screen_size[0] = window.innerWidth; this.properties.the_screen_size[1] =

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.