Hey all,
Here’s a funny one. I have two ViewControllers:
first one (fires on app load) – > displays a textField and a button.
When button is pressed, the text in the textField is to be passed on to the second ViewController through the action method of the button. the second ViewController is to display the text in a Label.
The string remains null 🙁
The label does not change 🙁
Other thing i did – inside the action method of the first ViewController – I created a new UILabel (you can’t see it here…), set its text field to the input i received from the user, then i set the second ViewController’s Label to be that one. The label still did not change, but at least the text field of the new label did change. If anyone could explain this to me as well, a=i’ll be happy to learn another new thing…
first controller code:
#import "FlipsideViewController.h"
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
UITextField *theTextInput;
}
@property (nonatomic, retain) IBOutlet UITextField *theTextInput;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)showInfo:(id)sender;
@end
the .m relevant part (“FlipsideViewController” is the secondViewController i mentioned):
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.textToTransmit.text = self.theTextInput.text;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
and this is the second ViewController:
#import <UIKit/UIKit.h>
@protocol FlipsideViewControllerDelegate;
@interface FlipsideViewController : UIViewController {
UILabel *textToTransmit;
id <FlipsideViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
@property (nonatomic, retain) IBOutlet UILabel *textToTransmit;
- (IBAction)done:(id)sender;
-(void)updateLabel:(NSString *)str;
@end
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
and it’s .m file:
#import "FlipsideViewController.h"
@implementation FlipsideViewController
@synthesize textToTransmit;
@synthesize delegate;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
}
- (IBAction)done:(id)sender {
[self.delegate flipsideViewControllerDidFinish:self];
}
....
Any of you who had the patience to read through my Q – I will be gratefull for an answer that will help me move forward.
regards,
Joe
reposition your line that sets the text, so that is after your
presentModalViewController: