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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:58:13+00:00 2026-05-26T20:58:13+00:00

the way to call a method has driven me really crazy! and unfortunately I

  • 0

the way to call a method has driven me really crazy! and unfortunately I couldn’t find it in the questions already asked.
I know how to alloc and init
but the thing is in my program I need to call the method inside its own class
here is a sample implementation, of course I know I could do this in dozen simpler ways but in the program I develop I have a much complex case that I need to do in this way

in my NIB file I have a label, and two buttons.
the label and one of the buttons (called “set to today”) are linked in appDelegate
the other button (called “set to ten days later”) is linked to classTwo
here are the codes for all the files
although the code doesn’t produce any error, but triggering the second button has no effect
what is the proper way to call that method.

AppDelegate.h:

@interface AppDelegate : NSObject <NSApplicationDelegate>
{
    IBOutlet NSTextField *label;
    NSDate *toDay;
}
-(IBAction)setToToday:(id)sender;
-(void)updateLabelText;
-(void)setToTenDays;

@property (assign) IBOutlet NSWindow *window;
@end

AppDelegate.m:

#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
-(IBAction)setToToday:(id)sender
{
    toDay=[NSDate date];
    [self updateLabelText]; 
}
-(void)updateLabelText
{
    [label setStringValue:[NSString stringWithFormat:@"%@",toDay]];
}
-(void)setToTenDays
{
    int secondsPerDay=60*60*24;
    toDay = [NSDate dateWithTimeInterval:10*secondsPerDay sinceDate:toDay];
}
@end

ClassTwo.h

@interface ClassTwo : NSObject
-(IBAction)setToTenDaysLater:(id)sender;
@end

ClassTwo.m

#import "ClassTwo.h"
#import "AppDelegate.h"
@implementation ClassTwo
-(IBAction)setToTenDaysLater:(id)sender
{
    AppDelegate *classOne=[[AppDelegate alloc] init];
    [classOne setToTenDays];
    [classOne updateLabelText];
}
@end

Why I can’t get the label set to new date?
both of the objects are in NIB file and actions and outlets are set
Thank you in advance for you kind helps.

P.S. in my real experience , for example I am using a trackpad event in CustomWindow Class to change the label.

  • 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-26T20:58:14+00:00Added an answer on May 26, 2026 at 8:58 pm

    Because in class two, you’re creating a new instance of AppDelegate, not calling the already-created one. You’re only supposed to have one NSApplicationDelegate anyway.

    You need to set up a reference to ClassOne from ClassTwo in the header file and connect them in the NIB, or set it programmatically, if you’re creating ClassTwo programmatically.

    Edit: I’ve added property accessors, make sure to read up on declared properties.

    @class AppDelegate;
    
    @interface ClassTwo : NSObject {
       AppDelegate *delegate;
    }
    
    @property (assign, nonatomic) IBOutlet AppDelegate *delegate;
    
    - (IBAction)setToTenDaysLater:(id)sender;
    
    @end
    

    ClassTwo.m

    #import "ClassTwo.h"
    #import "AppDelegate.h"
    
    @implementation ClassTwo
    
    @synthesize delegate;
    
    -(IBAction)setToTenDaysLater:(id)sender {
    
        [delegate setToTenDays];
        [delegate updateLabelText];
    }
    @end
    

    Then in ClassOne (AppDelegate) You could just set the delegate property like so:

    classTwo.delegate = self;
    

    Where classTwo is an IBOutlet to an archived instance in your XIB, or you could create it in code as well.

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

Sidebar

Related Questions

does anyone know a way to call a generic method of a base class
What I am looking for is a way to call a method after another
What's the best way to call a generic method when the type parameter isn't
What is the best way to call an instance method within an Expression Tree?
I was looking for a way to call the edit method directly. - (void)tableView:(UITableView
Opah! Is there any way I can call a method in the controller through
Quick question, is there a way to call your main method whatever you like
Is there a way to pass a call back function in a Java method?
I need to figure out the best way to call a statc method that
I am looking for a way to call a method on a new thread

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.