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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:21:37+00:00 2026-05-18T00:21:37+00:00

In my application i have some view controllers and one objective c class ,how

  • 0

In my application i have some view controllers and one objective c class ,how can i access the UI elemets of one view controller to change their values in objective class .

To explain further , i have a UILable *lab in the firstviewcontroller and just imported

#import "firstViewController.h"

in my customclass.m file and i am trying to do like this in one method of objective c class

 firstViewController.lab.text=@"example"; 

( i know its not correct method but i am trying to explain what i am doing )

can any one please tell me how can i do that ?

  • 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-18T00:21:38+00:00Added an answer on May 18, 2026 at 12:21 am

    First thing you need to do is grab a reference to the view controller you wish to operate on. One way to do this and have it available to other classes is to store a reference to it in a singleton object that you instantiate in your customclass.m. Specifically this is how this method works:

    Define Singleton Object:

    #import <Foundation/Foundation.h>
    
    @interface MySingleton : NSObject {
         MyViewController *myViewController;
    
    }
    @propery (nonatomic. retain) MyViewController *myViewController;
    +(MySingleton*)sharedMySingleton;
    
    @implementation MySingleton
    @synthesize myViewController;
    static MySingleton* _sharedMySingleton = nil;
    
    +(MySingleton*)sharedMySingleton
    {
        @synchronized([MySingleton class])
        {
            if (!_sharedMySingleton)
                [[self alloc] init];
    
            return _sharedMySingleton;
        }
    
        return nil;
    }
    
    +(id)alloc
    {
        @synchronized([MySingleton class])
        {
            NSAssert(_sharedMySingleton == nil, @"Attempted to allocate a second instance of a singleton.");
            _sharedMySingleton = [super alloc];
            return _sharedMySingleton;
        }
    
        return nil;
    }
    
    -(id)init {
        self = [super init];
        if (self != nil) {
            // initialize stuff here
        }
    
        return self;
    }
    
    @end
    

    Whereever you instantiate your myViewController you do this:

    #import "MySingleton.h"
    
    MySingleton *sinlgeton = [MySingleton sharedMySingleton];
    singleton.myViewController = myViewController;
    

    Now in your CustomClass.m you do this:

    #import "MySingleton.h"
    
        MySingleton *sinlgeton = [MySingleton sharedMySingleton];
        singleton.myViewController.lab.text = @"example"
    

    As I said this is ONE WAY to do this. However, you most probably DO NOT want to access and change view controller properties in a custom class so you should really rethink why you are doing this at all.

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

Sidebar

Related Questions

I have a problem I don't understand: Behind any View I have a controller
I am putting an iPad application together that allows a user to work their
I have a ASP.NET MVC 2.0 application using Entity Framework. All my views use
I have been working with rails3 and have been trying to create a simple
I have a form that creates a new brand. The user chooses a name,
Is it possible to expose the DataContext when extending a class in the DataContext?
This is a question with no real problem behind, just a product of my
I am trying to save few property into the plist when the user starts
Our assignment for our java project is to make a tool for kids to

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.