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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:35:14+00:00 2026-05-25T01:35:14+00:00

I have 4 classes i.e views in my application. Class A, having variable a

  • 0

I have 4 classes i.e views in my application. Class A, having variable a and b.

After clicking on button which is on view A of class A it leads to class B, which is table view controller. Then class B leads to class C. then class C leads to class D.

Now i want to access values of a and b of class A into class D. I tried it with NSNotification but not succeeded.

Please suggest.

I tried with NSNotification:

i tried with NSNotification like Class A—

-(IBAction) selectButton:(id) sender{



NSString * a = [NSString stringWithFormat:@"Manjinder singh"];
NSDictionary * dict = [NSDictionary dictionaryWithObject:a forKey:@"1"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"sendMessage" object:self userInfo:dict];

}  

Then Class D—-

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendMessage:) name:@"sendMessage" object:nil];
}
return self;
}




-(void)sendMessage:(NSNotification *)notification{


A *dil=[[A alloc] init];
nslog(@"dil.a");




NSLog(@"USERINFO:MyUserInfo (its a dictionary):%@",[[notification userInfo] valueForKey:@"1"]);

}

This is the rendom try but basically i want to show variable a and b of class A into class D.

Update:————
MyCoolViewController.h// a class where data send from

@protocol MyCoolViewDelegate;

@interface MyCoolViewController : UIViewController  {


id <MyCoolViewDelegate> delegate;//
}
@property (nonatomic, assign) id delegate;//


@end
@protocol MyCoolViewDelegate <NSObject>//

-(void)sendAStringToAnotherView:(NSString*)string;
@end

MyCoolViewController.m

-(void)viewDidLoad{

[delegate sendAStringToAnotherView:@"this is a string"];
}




firstViewController.m  //a class where data sent
-(void)viewDidLoad{

MyCoolViewController *myViewControllerPointer=[[MyCoolViewController alloc] init];
myViewControllerPointer.delegate = self;//
}

-(void)sendAStringToAnotherView:(NSString*)string
{
//displays the string as console output
NSLog(@"plzzzzzz show data",string);
}

value of string is not passed to this class because it is not showing in NSLog output.
UPDATED 2—

MyCoolViewController.m

#import “MyCoolViewController.h”
#import "firstViewController.h"


@implementation MyCoolViewController
@synthesize label1,sttr; 



@synthesize delegate;//







-(IBAction) selectButton:(id) sender{



if (curri==nil) {

     curri=[[CurrancyViewController alloc] initWithNibName:nil bundle:nil];



    [self.navigationController pushViewController:curri animated:YES];
}

      curri=nil;

  //CHECK ThIS  [curri release];
}






- (void)viewDidLoad
{
[delegate sendAStringToAnotherView:@"this is a string"];






self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background1.png"]];




[super viewDidLoad];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:  (UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }

@end
  • 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-25T01:35:15+00:00Added an answer on May 25, 2026 at 1:35 am

    Can you give more context about what specifically you are trying to achieve? It sounds like you want to pass data between several UIViewControllers. Here is how to set up a delegate for one of your view controllers:

    #import <UIKit/UIKit.h>
    
    @protocol MyCoolViewControllerDelegate;
    @interface MyCoolViewController : UIViewController {
        id <MyCoolViewControllerDelegate> delegate;
    }
    
    @property (nonatomic, assign) id delegate;
    
    @end
    
    @protocol MyCoolViewControllerDelegate <NSObject>
    
    -(void)sendAStringToAnotherView:(NSString*)string;
    
    @end
    

    Then you will should synthesize the delegate

    @synthesize delegate;
    

    and then when you want to pass data to, lets say a parent view, call this function:

    [delegate sendAStringToAnotherView:@"this is a string"];

    In the other view controller, wherever you instantiated the instance of this UIViewController, you need to set that self as the delegate;

    myViewControllerPointer.delegate = self;

    and then implement the delegate function in the parent view controller.

     -(void)sendAStringToAnotherView:(NSString*)string
    {
       //displays the string as console output
       NSLog(string);
    }
    

    The fact that you need communicate between views like this could possibly mean that there is a more efficient means of structuring your app. Can’t say for sure without more info.

    Try and use this template to add a delegate to your own app.

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

Sidebar

Related Questions

I have two view controller classes in my application delegate. I can change from
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I have classes which have automatic properties only like public customerName {get; set;}. They
If I have classes of Type A and B: public class A { public
In many application I often have algorithms which make use of dedicated sub-algorithms (or
I have two Domain classes (Drives & Computer) class Computer { static hasMany =
I have a simple ZF application (no modules) which works fine when I require
I have a ASP.NET MVC 2.0 application using Entity Framework. All my views use
I'm new to iphone development.I have practiced some view based application programs and console
I have three view controllers, one root controller, one login view controller and one

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.