-(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);
}
solved How to pass the NSString from One UIViewController to Another UIViewController? [duplicate]