I'm a newbie in iPhone Programming. I'm trying to send a message from one view controller to another. The idea is that viewControllerA takes information from the user and sends it to viewControllerB. viewControllerB is then supposed to display the information in a label.
viewControllerA.h
#import <UIKit/UIKit.h>
@interface viewControllerA : UIViewController
{
int num;
}
-(IBAction)do;
@end
viewControllerA.m
#import "viewControllerA.h"
#import "viewControllerB.h"
@implementation viewControllerA
- (IBAction)do {
//initializing int for example
num = 2;
viewControllerB *viewB = [[viewControllerB alloc] init];
[viewB display:num];
[viewB release];
//viewA is presented as a ModalViewController, so it dismisses itself to return to the
//original view, i know it is not efficient but it is not the problem with my code
[self dismissModalViewControllerAnimated:YES];
}
- (void)dealloc {
[super dealloc];
}
@end
viewControllerB.h
#import <UIKit/UIKit.h>
@interface viewControllerB : UIViewController
{
IBOutlet UILabel *label;
}
- (void)display:(int)myNum;
@end
viewControllerB.m
#import "viewControllerB.h"
#import "viewControllerA.h"
@implementation viewControllerB
- (void)display:(int)myNum {
NSLog(@"YES");
[label setText:[NSString stringWithFormat:@"%d", myNum]];
}
@end
YES is logged successfully, but the label's text does not change. Can sent messages not access instance variables or something?
Thanks.