I'm making elevator thing. I'm having trouble sending data with different views using presentModalViewController. I got red message "favoriteColorString" property not found. I copied exactly the same but different form names and buttons. The "favoriteColorString" appears an error and unable to send elevator2 data.
I tried two different thing.
Elevator2View.favoriteColorString = [[NSString alloc] initWithFormat:@"Your favorite color is %@", favoriteColorTextField.text];
And
favoriteColorString = [[NSString alloc] initWithFormat:@"Your favorite color is %@", favoriteColorTextField.text];
Here's my code:
ElevatorView.h
#import <UIKit/UIKit.h>
#import "Elevator2View.h"
@interface ElevatorView : UIViewController<PassSecondColor>
{
Elevator2View *Elevator2View;
IBOutlet UITextField *favoriteColorTextField;
IBOutlet UILabel *favoriteColorLabel;
IBOutlet UILabel *secondFavoriteColorLabel;
NSString *secondFavoriteColorString;
}
@property (nonatomic, retain) Elevator2View *Elevator2View;
@property (nonatomic, retain) IBOutlet UITextField *favoriteColorTextField;
@property (nonatomic, retain) IBOutlet UILabel *favoriteColorLabel;
@property (nonatomic, retain) IBOutlet UILabel *secondFavoriteColorLabel;
@property (copy) NSString *secondFavoriteColorString;
@end
ElevatorView.m
#import "ElevatorView.h"
#import "Elevator2View.h"
@implementation ElevatorView
@synthesize Elevator2View, favoriteColorTextField, favoriteColorLabel, secondFavoriteColorLabel;
@synthesize secondFavoriteColorString;
-(IBAction)level1:(id)sender;{
favoriteColorTextField.text = @"1";
Elevator2View.favoriteColorString = [[NSString alloc] initWithFormat:@"Your favorite color is %@", favoriteColorTextField.text];
[self presentModalViewController:[[[Elevator2View alloc] init]
autorelease] animated:NO];
}
Elevator2View.h
#import <UIKit/UIKit.h>
@protocol PassSecondColor <NSObject>
@required
- (void) setSecondFavoriteColor:(NSString *)secondFavoriteColor;
@end
@interface Elevator2View : UIViewController{
IBOutlet UITextField *secondFavoriteColorTextField;
IBOutlet UILabel *favoriteColorLabel;
IBOutlet UILabel *secondFavoriteColorLabel;
NSString *favoriteColorString;
id <PassSecondColor> delegate;
}
@property (copy) NSString *favoriteColorString;
@property (nonatomic, retain) IBOutlet UITextField *secondFavoriteColorTextField;
@property (nonatomic, retain) IBOutlet UILabel *favoriteColorLabel;
@property (nonatomic, retain) IBOutlet UILabel *secondFavoriteColorLabel;
@property (retain) id delegate;
@end
Elevator2View.m
#import "Elevator2View.h"
@interface Elevator2View ()
@end
@implementation Elevator2View
@synthesize secondFavoriteColorTextField, favoriteColorLabel, secondFavoriteColorLabel;
@synthesize favoriteColorString;
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void) viewWillAppear:(BOOL)animated
{
favoriteColorLabel.text = favoriteColorString;
}
- (void) viewWillDisappear:(BOOL) animated
{
// [[self delegate] setSecondFavoriteColor:secondFavoriteColorTextField.text];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
favoriteColorLabel.text = favoriteColorString;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end