Я уверен, что этому есть простое объяснение.Я хочу передать данные (не хранить), но перенести текст, который пользователь вводит в текстовое поле и отобразить его как UILabel в другом ViewController.Я уже знаю, как преобразовать текст, введенный пользователем, в метку на том же viewcontroller.Я предполагаю, что моя проблема заключается в импорте.
.h:
@interface ViewController : UIViewController {
IBOutlet UITextField *firstPerson;
IBOutlet UITextField *secondPerson;
IBOutlet UIButton *calculateButton;
NSString *firstName;
NSString *secondName;
}
@property (nonatomic, retain) IBOutlet UITextField *firstPerson;
@property (nonatomic, retain) IBOutlet UITextField *secondPerson;
@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *secondName;
@property (nonatomic, retain) IBOutlet UIButton *calculateButton;
-(IBAction)calculate;
@end
.m:
-(IBAction)calculate {
//Linked to UIButton
//This is the first View Controller.
// firstName = firstPerson.text;
// secondName = secondPerson.text;
secondViewController = [[ShowStats alloc] init];
}
моего контроллера второго просмотра .m (ShowStats):
#import "ShowStats.h"
#import "ViewController.h"
- (void)viewDidLoad
{
firstName = firstPerson.text;
secondName = secondPerson.text;
[super viewDidLoad];
}
Большое спасибо! РЕДАКТИРОВАТЬ
ViewController.h
#import <UIKit/UIKit.h>
#import "ShowStats.h"
@interface ViewController : UIViewController {
IBOutlet UITextField *firstPerson;
IBOutlet UITextField *secondPerson;
IBOutlet UIButton *calculateButton;
//NSString *firstName;
// NSString *secondName;
}
@property (nonatomic, retain) IBOutlet UITextField *firstPerson;
@property (nonatomic, retain) IBOutlet UITextField *secondPerson;
//@property (nonatomic, retain) NSString *firstName;
//@property (nonatomic, retain) NSString *secondName;
@property (nonatomic, retain) IBOutlet UIButton *calculateButton;
-(IBAction)calculate;
@end
ViewController.m
#import "ViewController.h"
#import "ShowStats.h"
@implementation ViewController
@synthesize firstPerson, secondPerson;
//@synthesize firstName, secondName;
@synthesize calculateButton;
ShowStats *secondViewController;
-(IBAction)calculate {
secondViewController = [[ShowStats alloc] init];
secondViewController.firstName = firstPerson.text;
}
ShowStats.h
@interface ShowStats : UIViewController{
IBOutlet UILabel *nameStats;
}
@property (nonatomic, retain) IBOutlet UILabel *nameStats;
@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *secondName;
@end
ShowStats.m
- (void)viewDidLoad
{
nameStats.text = [NSString stringWithFormat:@"%@", firstName];
//secondLabel.text = self.secondName;
[super viewDidLoad];
}