- How to pass a variable to the next view?
- @property (nonatomic, strong) NSNumber *correctAnswers;
- -(IBAction)nextPage{
- int antalratt = 12; // Value to be transfered
- FirstViewController * fvc = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
- fvc.answer = antalratt;
- [self presentModalViewController:fvc animated:YES];
- [fvc release];
- }
- @interface FirstViewController : UIViewController
- {
- int answer;
- }
- @property(nonatomic,assign) int answer;
- @implementation FirstViewController
- @synthesize answer;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSLog(@"%d",answer); // //displays answer on log
- }
- @end
- @interface AppDelegate : UIResponder <UIApplicationDelegate>
- {
- int antalratt;
- }
- @property(nonatomic ,assign) int antalratt;
- -(IBAction)nextPage{
- int antalratt = 12; // Value to be transfered
- AppDelegate * delegate = [[UIApplication sharedApplication] delegate];
- delegate.antalratt = antalratt;
- FirstViewController * fvc = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
- [self presentModalViewController:fvc animated:YES];
- [fvc release];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- AppDelegate * delegate = [[UIApplication sharedApplication] delegate];
- NSLog(@"%d",delegate.antalratt); //displays answer on log
- }
- -(IBAction)nextPage{
- int antalratt = 12; // Value to be transfered
- [[NSUserDefaults standardUserDefaults] setInteger:antalratt forKey:@"answer"];
- FirstViewController * fvc = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
- [self presentModalViewController:fvc animated:YES];
- [fvc release]; }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- int ans = [[[NSUserDefaults standardUserDefaults] objectForKey:@"answer"] intValue];
- NSLog(@"%d",ans); //displays answer on log
- }
- filename *detailViewController = [[filename alloc] initWithNibName:@"filename" bundle:nil];
- detailViewController.audio=@"yourData";
- [self presentModalViewController:detailViewController animated:YES];
- [detailViewController release];
- NSString *audio;
- @property(nonatomic,retain) NSString *audio;
- @synthesize audio;
- -(void) ViewDidLoad
- {
- NSLog(@"Audio = %@",audio); // if ur variable is integer declare %d in nslog.
- }
- @interface view1 : UIView{
- NSString *passingVariable;
- }
- @property (nonatomic, strong) NSString *passingVariable;
- @end
- view1.m
- @synthsize passingVariable;
- @implementation view1
- @end
- view2.m
- #import "view1.h"
- @implementation view2
- -(IBAction)changeview
- {
- view1 *myview = [[view1 alloc]init];
- myview.passingVariable = [NSString stringWithString:@"Hello Variable"];
- [self.navigationController pushViewController:myview animated:YES];
- }
- @end