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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:48:57+00:00 2026-05-28T20:48:57+00:00

I have two views which are created programmatically. Let’s name them view1 and view2.

  • 0

I have two views which are created programmatically. Let’s name them view1 and view2. In view1 there is a picker and a button. The idea is when the user choose value and press the button selected value to be accessable from view2. For this I use NSNotificationCenter. Here is some code.

view1.m

-(void)registerNotification
{
    NSDictionary *dict = [NSDictionary dictionaryWithObject:self.selectedOption forKey:@"data"];

    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"pickerdata" 
     object:self
     userInfo:dict];
}

-(void)loadSecondView
{
    self.secondView = [[secondViewController alloc]init];
    [self.view addSubview:self.secondView.view];
    [self registerNotification];
    [self.secondView release];
}

view2.m

-(id)init
{
   if(self = [super init])
   {
    [[NSNotificationCenter defaultCenter] 
         addObserver:self 
         selector:@selector(reciveNotification:) 
         name:@"pickerdata" object:nil];
   }
   return self;
}


-(void)reciveNotification:(NSNotification *)notification
{
    if([[notification name] isEqualToString:@"pickerdata"])
    {
        NSLog(@"%@", [NSString stringWithFormat:@"%@", [[notification userInfo] objectForKey:@"data"]]); // The output of NSLog print selected value

       // Here is assignment to ivar
        self.selectedValue = [NSString stringWithFormat:@"%@", [[notification userInfo] objectForKey:@"data"]];
    }
}

The problem starts here. The logic which is interested of that value is implemented in loadView method. The problems is that loadView is executed before reciveNotification method and selectedValue does not contain needed information yet.
What to do so the information provided from NSNotificationCenter to be accessible from loadView method ?

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

    I don’t know if I fully understand your question, but wouldn’t it be easier to pass the value directly to the viewController instead of dealing with notifications?

    -(void)loadSecondView
    {
        self.secondView = [[secondViewController alloc]init];
        self.secondView.selectedValue = self.selectedOption;
        [self.view addSubview:self.secondView.view];
        [self.secondView release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two views in SQL, and have created mappings to them in Linq
I have created two options for a query used in a view which return
I have two views which will both use the same Controller method: //webServiceController.cs //The
i have two image views which translates on click. the animation works properly for
I've created a simple navigation application, which alternates between two views through the use
I have two view controllers in a tabbar which can both edit data. Therefore,
I have a view table which is a union of two separate tables (say
I have a view that contains two NSTextFieldCell s. The size at which these
I have two views, one view takes the whole screen, the second view covers
I have two views within one .xib (one view for landscape, another for portrait).

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.