Hi All
I have a TabBar applications and one of the tab items is called Newsletter.
I want to programmatically change a label in the NewsletterView.
Here is my header file for the view:
Code:
//
// NewsletterViewController.h
#import <UIKit/UIKit.h>
@interface NewsletterViewController : UIViewController {
IBOutlet UILabel *myLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
@end
and here is my implementation:
Code:
//NewsletterViewController.m
#import "NewsletterViewController.h"
@implementation NewsletterViewController
@synthesize myLabel;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
myLabel.text = @"test";
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
In interface builder I opened NewsletterViewController.xib and have added a UILabel.
It would not allow my to connect this to "myLabel" so i added an object and made is a class of NewsletterViewController, this allowed me to connect the UILabel to the myLabel outlet.
I have used the code to change the text, but this doesn't do anything.
Code:
- (void)viewDidLoad {
[super viewDidLoad];
myLabel.text = @"test";
}
Everything compiles cleanly.
Can you offer any advice, am i linking the Label correctly? should my label be in my delegate?
Thanks