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

  • Home
  • SEARCH
  • 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 9035521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:46:40+00:00 2026-06-16T08:46:40+00:00

I try to access a public method from another class. I already tried many

  • 0

I try to access a public method from another class. I already tried many examples I found in the web, but they didn’t work in the way I wanted them to.

Class1.h

@interface anything : NSObject {

    IBOutlet NSTextField *label;

}

+ (void) setLabel:(NSString *)string;
- (void) changeLabel:(NSString *)string2;

Class1.m

+ (void) setLabel:(NSString *)string {

    Class1 *myClass1 = [[Class1 alloc] init];

    [myClass1 changeLabel:string];
    NSLog(@"setLabel called with string: %@", string);

}

- (void) changeLabel:(NSString *)string2 {

    [label setStringValue:string2];
    NSLog(@"changeLabel called with string: %@", string2);
}

Class2.m

- (IBAction)buttonPressed {

    [Class1 setLabel:@"Test"];

}

Very strange is that in the NSLogs, everything is fine, in both NSLogs, the string is “Test”, but the textField’s stringValue doesn’t change!

  • 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-16T08:46:41+00:00Added an answer on June 16, 2026 at 8:46 am

    Here a short example for what you can do:


    The Custom Class

    @interface ITYourCustomClass : NSObject
    @property (strong) NSString *title;
    
    - (void)doSomethingWithTheTitle;
    @end
    
    @implementation ITYourCustomClass
    - (void)doSomethingWithTheTitle {
        NSLog(@"Here's my title: %@", self.title);
    }
    @end
    

    Using it

    @implementation ITAppDelegate
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        ITYourCustomClass *objectOfYourCustomClass = [[ITYourCustomClass alloc] init];
        [objectOfYourCustomClass doSomethingWithTheTitle];
    }
    
    @end
    

    Class and object methods

    Declaring a method with + means, that you can call the method directly on a class.
    Like you did it with [myClass1 setLabel:@"something"];.
    This doesn’t make sense. What you want, is creating a property.
    A property is saved in an object, so you can create an object ITYourCustomClass *objectOfYourCustomClass = [[ITYourCustomClass alloc] init]; and setting the properties objectOfYourCustomClass.title = @"something". Then you can call [objectOfYourCustomClass doSomethingWithTheTitle];, which is a public object method.

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

Sidebar

Related Questions

I try to access the MainContentBlock control from the aspx, but unable to do
I have a method which takes an array as a parameter from another class:
The error message I gen when I try to access the web page server
A child class can access protected functions in parent class,but the parent class can't
I am receiving an error on me method to allow a class access to
My problem lies with trying to access Scanner scan created in one method from
I have the following method: class MyClass { public: MyClass; bool method (MyClass &obj);
I'm trying to duplicate a file from a bucket to another but I can't
I try to access session variables stored on a different page. When I have
When try to access site i created after 3 login attempts it gives unauthorised

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.