I have a table view which loads another xib file and uses the content of that new xib file to display the header. In this new xib I have a UIImageView and a label. I want to be able to change the image and the label from view did load. I have linked up everything in interface builder properly. It just won’t change the image or the text label.
Header file
////h file///
#import <UIKit/UIKit.h>
#import "MyProfile.h"
@interface MainMenu : UITableViewController
{
IBOutlet UIView *headerView;
UIImageView *imageview;
UILabel *label;
}
@property (nonatomic, retain) IBOutlet UIImageView *imageview;
@property (nonatomic, retain) IBOutlet UILabel *label;
-(UIView *)headerView;
-(IBAction)fn:(id)sender;
@end
Partial .m file
///// partial .m file////
-(UIView *)headerView
{
if(!headerView)
{
[[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil];
}
return headerView;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection: (NSInteger)section
{
return [self headerView];
}
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return [[self headerView] bounds].size.height;
}
-(id) init
{
self = [super initWithStyle:UITableViewStyleGrouped];
return self;
}
- (id)initWithStyle:(UITableViewStyle)style
{
return [self init];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[self navigationItem] setTitle:@"The Table"];
menuitems = [[NSMutableArray alloc] init];
[menuitems addObject:@"item one"];
[menuitems addObject:@"item two"];
fieldnames = [[NSMutableArray alloc] init];
[fieldnames addObject:@"Date of Birth"];
[fieldnames addObject:@"Nationality"];
label.text = @"new label value will not be displayed!";
}
Why won’t the text label update?
I have set the header view’s xib file’s owner to be the main menu and I have connected the label in header view.xib up to the IBOutlet.
Thanks.
Ok I solved it. I don’t know If this is the way that you are supposed to do it but it works.
If you stick
in
and then reload the xib inside viewdidload:
it works. Is this the way you are supposed to do it?
Thanks