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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:27:28+00:00 2026-05-26T22:27:28+00:00

I am trying to pass a string back and forth between the view Controllers,

  • 0

I am trying to pass a string back and forth between the view Controllers, so for example as soon as I click on a tab bar button (+) in the first View, second view opens (PresentModalViewController) and it has a Text Field. So anything I type, I take it into a string(this string is an object of the first view) and I am trying to append that string to a tableview loaded in the first View.

Note: My string object is declared like this

View1.h

NSString *string 

@property (copy) NSString *string;

View1.m

@synthesize string;

And in the View 2 I am passing the textField Value like this

View2.m

View1 *view1 = [[View1 alloc] initWithNibName:@"View1" bundle:nil];
view1.string = [[NSString alloc] initWithFormat:@"%@", TextField.text];

Problem – When I NSLog this value inside the View2, it grabs the value from the Text Field but in order for me to load the previous view, I need to dismiss this View2. So as soon as this View2 is dismissed when I try to access the same string object in my view 1. It says the string object is null.

Question – Could someone tell me
1. How to get the text Field value from view 2 to view 1 after dismissing View 2 (does it really makes all its objects null when dismissed?)
2. How to append that string to the last index of a NSMutableArray?

  • 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-26T22:27:28+00:00Added an answer on May 26, 2026 at 10:27 pm

    This is a very good question that I also had trouble figuring out when I started coding for the iOS. Basically, you don’t need to initialize a new view1 because the tabbar controller already holds the view1 object in its viewControllers property. Also, alloc/init’ing the string in not necessary in this situation.

    Therefore, you would want to change this:

    View1 *view1 = [[View1 alloc] initWithNibName:@"View1" bundle:nil];
    view1.string = [[NSString alloc] initWithFormat:@"%@", TextField.text];
    

    To something like this:

    View1 *view1 = [self.tabbarController.viewControllers objectAtIndex:0];
    view1.string = textField.text;
    

    Or even:

    ((View1 *)[self.tabbarController.viewControllers objectAtIndex:0]).string = textField.text;
    

    Part 2:

    How to append that string to the last index of a NSMutableArray?

    NSMutableArray *someArray = [[NSMutableArray alloc] init];
    [someArray addObject:string];
    [someArray addObject:@"anotherString"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass a string over to a detail view of my
I'm trying to pass a string to chdir(). But I always seem to have
I'm trying to pass a string argument to a target function in a process.
i'm trying to pass a string from main to another function. this string is
I'm trying to pass the following String to a PreparedStatement : private static final
I'm trying to pass a userId (string) in the URL which will be passed
I'm trying to pass in a Base64 string into a C#.Net web application via
I am currently trying to pass a generated JSON string to dojo for parsing
im trying to pass back from a user control a list of strings that
i am trying to pass an arraylist back to my parent activity Here is

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.