This is my hole code which I am using, I want to transfer scrollViewCintroller Class value in the page2 class.
scrollAppDelegate.h
@class scrollViewController;
@interface scrollAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
scrollViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet scrollViewController *viewController;
@end
scrollAppDelegate.m
#import "scrollAppDelegate.h"
#import "scrollViewController.h"
@implementation scrollAppDelegate
@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions {
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
scrollViewController.h
#import <UIKit/UIKit.h>
#import "result.h"
#import "page2.h"
@interface scrollViewController : UIViewController{
IBOutlet UITextField *txtName;
}
@property (nonatomic, retain) UITextField *txtName;
- (IBAction) next :(id)sender;
scrollViewController.m
#import "scrollViewController.h"
@implementation scrollViewController
@synthesize txtName;
-(IBAction)next:(id)sender
{
objPage2=[[page2 alloc]initWithNibName:@"page2" bundle:nil];
[self.view addSubview:objPage2.view];
}
@end
I want to use this txtName in other page2 class
page2.h
#import <UIKit/UIKit.h>
@interface page2 : UIViewController {
}
@end
page.m
#import "page2.h"
@implementation page2
This is making a new page1 object. None of the variables you have assigned previously will be available. Your page2 object needs to have a pointer to the actual page1 object you have been using before, it should either be passed in when creating page2 or obtained from the navigation controller or similar, it is not possible to say more without knowIng the structure of your app.
EDIT
OK, after your additional code I would suggest the following:
Create a property on your page2 object which refers back to your page 1. Let’s call it page1.
In your page2.h:
page2.m:
When you create your page2 object when the button is pressed, pass the text across at this point:
This line goes between your alloc and when you add it to the subview.
You will also need to move
#import "page2.h"from your scrollViewController.h to your scrollViewController.m, and put@class scrollViewController;in your page2.h, and#import "scrollViewController.h"in your page2.m