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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:31:47+00:00 2026-06-06T09:31:47+00:00

I am creating a simple iPhone navigation based application. In this I am moving

  • 0

I am creating a simple iPhone navigation based application. In this I am moving to second class from first class. In the second class I am setting some values to the string(selectedName). And when I go back to the first class in (void)ViewWillAppear, I am accessing the value of the selectedString by the object of that class. I have already allocated the object of second class in first class in –(void)ViewDidLoad method, but it logs null value there. Please help me out.

In second class i have a string named selectedString i m setting some values to it.and logs it ,it logs fine.

In first class viewDidLoad method i have allocated the object of second class like this

  Second *obj=[Second alloc]initWithNibName:@"Second" bundle:nil];

in the viewWillAppear metode i m accesing the selectedString like this ,but it logs null.

 NSLog(@"%@",obj.selectedString);                              
  • 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-06T09:31:48+00:00Added an answer on June 6, 2026 at 9:31 am

    Try this for Passing Data Back:

    To pass data back from ViewControllerB to ViewControllerA you need to use Protocols and Delegates.

    To do this we will make ViewControllerA a Delegate of ViewControllerB, this allows ViewControllerB to send a message back to ViewControllerA enabling us to send data back.

    For ViewControllerA to be delegate of ViewControllerB it must conform to ViewControllerB’s protocol which we have to specify. This tells ViewControllerA which methods it must implement.

    1) In ViewControllerB.h below the #import but above @interface you specify the protocol.

    @protocol ViewControllerBDelegate <NSObject>
    - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item;
    @end
    

    2) next still in the ViewControllerB.h you need to setup a delegate property and synthesize in ViewControllerB.m

    @property (nonatomic, weak) id <ViewControllerBDelegate> delegate;
    

    3) In ViewControllerB we call a message on the delegate when we pop the viewcontroller.

    NSString *itemToPassBack = @"Pass this value back to ViewControllerA";
    [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];
    

    4) Thats it for ViewControllerB, now in ViewControllerA.h tell ViewControllerA to import ViewControllerB and conform to its protocol.

    #import "ViewControllerB.h"
    
        @interface ViewControllerA : UIViewController <ViewControllerBDelegate>
    

    5) In ViewControllerA.m implement the following method from our protocol

    - (void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
    {
         NSLog(@"This was returned from ViewControllerB %@",item);
    }
    

    6) The last thing we need to do is tell ViewControllerB that ViewControllerA is its delegate before we push ViewControllerB on to nav stack.

    ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib=@"ViewControllerB" bundle=nil];
    viewControllerB.delegate = self
    [self pushViewController:viewControllerB animated:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m creating a simple GUI navigation based application in iphone. When this application
I'm creating a simple Navigation-based app using core data for my iPhone and I'm
Was creating a simple console application to do some prototyping and was shocked to
Creating some simple html pages specific for the iphone, and would like to use
friends, I am new to Iphone development, I am creating a simple analog clock,
i am creating simple call filter application which restrict unwanted calls. i use following
Creating a simple RPG game, first time using XNA. Trying to get my character
I am creating a simple application with Django. I realized that I am doing
I am creating a simple FeedReader iPhone app where a RSS is feed is
what i am trying to do is, i am creating a very simple iphone

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.