I am new to objective C and I have a c++ background. I want to display a value in the label on the screen. I am calling the label value from the MainView.m. However, the label becomes blank after I click a button instead of printing a value. What is the problem? Here is the code.
MainView.h
@interface MainView : UIView { int a; }
-(int) vr;
@end
MainView.m
-(int) vr { return 100; }
@end
MainViewController.h
@interface MainViewController : UIViewController {
IBOutlet UILabel *myLabel;
NSMutableString *displayString;
MainView *view1; }
@property (nonatomic, retain) UILabel *myLabel;
@property (nonatomic, retain) NSMutableString *displayString;
(IBAction)showInfo;
(IBAction) pressButton:(id) sender;
@end
MainViewController.m
@synthesize myLabel, displayString;
-(IBAction) pressButton:(id) sender{
[displayString appendFormat:@"%i", view1.vr];
myLabel.text = displayString;}
- (void)viewDidLoad {
view1 = [[MainView alloc] init];
[super viewDidLoad];}
- (void)dealloc {
[view1 dealloc];
[super dealloc];}
I have not mentioned code that had been auto generated. This is enough to get the whole picture. I tried a lot to debug this thing. I believe that IBAction carries out direct command such that
myLabel.text = @"string";
but it does not invoke any method or class. Any subtle ideas? Thanks.