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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:12:43+00:00 2026-06-11T13:12:43+00:00

Possible Duplicate: iOS – Passing variable to view controller I have two Viewcontrollers (ViewController1

  • 0

Possible Duplicate:
iOS – Passing variable to view controller

I have two Viewcontrollers (ViewController1 and ViewController2) , And i want to pass a String value along with a IBAction from ViewController1 to ViewController2. I am trying to read the NSString (*check) value in ViewController2’s ViewDidLoad method, but it’s returning a null value.

Help me out and Thanks in advance.

// ViewController1

@interface ViewController1 : UIViewController {

        IBOutlet UIButton *btn1;
        IBOutlet UIButton *btn2;
        NSString *check;
    }
#import "ViewController.h"

-(IBAction)buttonClicked:(id)sender {

    check = [[NSString alloc] init];

    if (btn1.tag == 0) {
        check = @"foo";
        NSLog(@"%@",check);    
    }
    if (btn2.tag == 1) {
        check = @"bar";
        NSLog(@"%@",check);
    }
} 

in my second view controller ,

#import <UIKit/UIKit.h>

@class ViewController1;

@interface ViewController2 : UIViewController {

    ViewController1 *viewCon;
}

@property(nonatomic,retain) ViewController *viewCon;

//.m

#import "ViewController2.h"
#import "ViewController1.h"

@synthesize viewCon,

 - (void)viewDidLoad
{
    ViewController *myVC = [[ViewController alloc] init];
    NSLog(@"  Label  %@",myVC.check);
    [super viewDidLoad];
}
  • 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-11T13:12:44+00:00Added an answer on June 11, 2026 at 1:12 pm
    -(IBAction)buttonClicked:(id)sender {
    
       //check = [[NSString alloc] init]; -- NO Need
    
        if (btn1.tag == 0) {
            check = @"foo";
            NSLog(@"%@",check);    
        }
        if (btn2.tag == 1) {
            check = @"bar";
            NSLog(@"%@",check);
        }
    
      ViewController2 *obj = [[ViewController2 alloc] initWithNibName:@"ViewController2"];
      [obj setCheck:check];
      //push to ViewController2
      [obj release];
    

    }

    In your second view controller,

    #import <UIKit/UIKit.h>
    
    @interface ViewController2 : UIViewController {
    
            NSString *check;
    }
    @property (nonatomic, retain) NSString *check;
    
    
    //.m
    
    #import "ViewController2.h"
    
    @synthesize check;
    
    
     - (void)viewDidLoad
    {
        NSLog(@"  Label  %@",check);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: iPhone development on PC I have developed an iOS native application. My
Possible Duplicate: IOS: one account two iOS developer program excuse me if it's not
Possible Duplicate: saving data in iOS Do we have a provision profile to select
Possible Duplicate: How to parse JSON in iOS App I have the following json:
Possible Duplicate: iOS: to ARC or not to ARC? Pros and Cons i have
Possible Duplicate: UISlider and UIScrollView using iOS SDK 4.3. I've found when I have
Possible Duplicate: Is there a barcode recognition framework for iOS? i want to develop
Possible Duplicate: Getting current device language in iOS? I have an app which uses
Possible Duplicate: iOS 6 and Location Services not working Our app's location services have
Possible Duplicate: Check iPhone iOS Version I want to check iOS Version in iOS.

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.