2011-10-12 86 views
0

我在tableview中使用了自定義的sectionheader類,並在旋轉後獲取了一些意想不到的行爲。這裏的用例:對細胞自定義SectionHeaderView在景觀中保留在縱向視圖中

  1. 輕按的UITableView
  2. 查看壓入堆棧。
  3. 將視圖旋轉到橫向。
  4. 旋轉回肖像。
  5. 彈出視圖。
  6. 在iPhone 3G 上只有,橫向尺寸的部分標題現在出現在視圖中間的某個位置(除了縱向大小的部分標題,它應該出現在視圖的頂部)實現代碼如下)。多餘的頭文件與UITableView單元格一起滾動,並且離開並返回到視圖(UITableView嵌套在UITabBarController中)並不能解決問題。

我無法在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

作爲第一步,我會建議用默認的替換自定義標題視圖並查看是否出現問題。如果是這樣,那麼它可能是一個iOS錯誤。 – Akshay

+0

使用默認替換自定義標題視圖會導致相同的問題。如果這真的是一個iOS的bug,我只是感到驚訝,這是以前沒有見過的 - 它不像是爲iPhone 4發明的部分頭文件... – beaudrykock

回答

0

仍然不知道是什麼原因導致了這個問題,但我最終通過在viewWillAppear中添加一個檢查來確保舊標題被刪除,從而解決了這個問題。