我正在使用带有tableview的自定义sectionheader类,并在旋转后获得一些意外行为。这是用例:
我无法在iPhone 4或模拟器中重现此问题。看起来,出于某种原因,在弹出第二级视图后,面向横向的sectionheaderview被添加到uitableview,但为什么会这样呢?请注意,使用默认(而非自定义)标头时会再现相同的问题。我还检查了设备方向是否被错误地返回是一个问题,而且似乎并非如此。
这是自定义SectionHeaderView类的初始化代码,如果它有用:
-(id)initWithFrame:(CGRect)frame title:(NSString*)title delegate:(id <SectionHeaderViewDelegate>)aDelegate {
self = [super initWithFrame:frame];
if (self != nil) {
float lineHeight = 0.5f;
// check line sizing for retina/non-retina
if (![Utilities hasRetina])
{
lineHeight = 1.0f;
}
// Set up the tap gesture recognizer.
delegate = aDelegate;
// Create and configure the title label.
CGRect titleLabelFrame = self.bounds;
titleLabelFrame.origin.y -= 12.5;
titleLabel = [[UILabel alloc] initWithFrame:titleLabelFrame];
titleLabel.text = title;
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.font = [UIFont fontWithName:@"Georgia" size:15.0];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
[self addSubview:titleLabel];
// add thin white line to top of section header
UIView *topBorder = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.bounds.size.width, lineHeight)];
[topBorder setBackgroundColor:[UIColor whiteColor]];
[self addSubview:topBorder];
[topBorder release];
// Set the colors for the gradient layer.
static NSMutableArray *colors = nil;
if (colors == nil) {
colors = [[NSMutableArray alloc] initWithCapacity:3];
UIColor *color = nil;
color = [UIColor colorWithRed:57.0/255.0 green:56.0/255.0 blue:105.0/255.0 alpha:1.0];
[colors addObject:(id)[color CGColor]];
color = [UIColor colorWithRed:54.0/255.0 green:53.0/255.0 blue:95.0/255.0 alpha:1.0];
[colors addObject:(id)[color CGColor]];
color = [UIColor colorWithRed:57.0/255.0 green:56.0/255.0 blue:105.0/255.0 alpha:1.0];
[colors addObject:(id)[color CGColor]];
}
[(CAGradientLayer *)self.layer setColors:colors];
[(CAGradientLayer *)self.layer setLocations:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.48], [NSNumber numberWithFloat:1.0], nil]];
}
return self;
}
为什么在纵向视图中添加自定义SectionHeaderView的附加横向版本,仅在iPhone 3G上添加?
提前感谢您的帮助。
答案 0 :(得分:0)
仍然不知道是什么导致了这个问题,但我最终通过在viewWillAppear中添加一个检查来解决它,以确保删除了旧标头。