I've got a header/brand image which changes between iPad and iPhone, but will not change the picture when changing from portrait to landscape, which is really important that it does.
I have this HeaderView Class, which is called by tableViewControllers like this:
self.tableView.tableHeaderView = [[HeaderView alloc] initWithText:@""];
which holds a UIImageView:
@interface HeaderView : UIImageView{
}
- (id)initWithText:(NSString*)text;
- (void)setText:(NSString*)text;
@end
For the M file, we find where I'm not getting the result I want:
#import "HeaderView.h"
#define IDIOM UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
@interface HeaderView()
{
UILabel*label;
}
@end
@implementation HeaderView
- (id)initWithText:(NSString*)text
{
UIImage* img = [UIImage imageNamed:@"WashU.png"];
UIImage* iPhonePortrait = [UIImage imageNamed:@"WashU2.png"];
UIImage* image = [[UIImage alloc] init];
UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
//different header image for different devices...
if(IDIOM==IPAD){
image = img;
}
else{
if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){
image = iPhonePortrait;
}
else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
iPhonePortrait = nil;
image = img;
}
}
[headerImageView setImage:image];
if (self = [super initWithImage:image]){
}
return self;
}
I also have added these methods:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
-(BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
I'm sure its a classic sort of question, but I'm reasonably stumped. Also, if I remove
[headerImageView setImage:image];
, and
[self addSubview:headerImageView];
, the image still shows up, which means that
if (self = [super initWithImage:image])
is doing all the display work.