2012-05-14 40 views
0

我在iPad上有一些奇怪的行爲,我沒有在iPhone上獲得。部分的UITableView頭僅在滾動時出現

我有一個分區表視圖,有部分和標題的部分,問題是,在iPad上最頂端的部分的標題不顯示,當向下滾動表的部分標題出現一小會兒之前屏幕。

之前滾動

http://desmond.imageshack.us/Himg525/scaled.php?server=525&filename=screenshot2012051410074.png&res=landing http://desmond.imageshack.us/Himg525/scaled.php?server=525&filename=screenshot2012051410074.png&res=landing

滾動

http://desmond.imageshack.us/Himg59/scaled.php?server=59&filename=screenshot2012051410074.png&res=landing http://desmond.imageshack.us/Himg59/scaled.php?server=59&filename=screenshot2012051410074.png&res=landing

的代碼創建部分的標題後:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section]; 
    if (sectionTitle == nil || [sectionTitle isEqualToString:@""]) { 
     return nil; 
    } 

    // Create label with section title 
    UILabel *label = [[UILabel alloc] init] ; 
    label.frame = CGRectMake(12, 0, 300, 30); 
    label.backgroundColor = [UIColor clearColor]; 
    label.textColor = [UIColor blackColor]; 
    label.shadowColor = [UIColor whiteColor]; 
    label.shadowOffset = CGSizeMake(0.0, 1.0); 
    label.font = [UIFont boldSystemFontOfSize:16]; 
    label.text = sectionTitle; 

    UIImage *img = [UIImage imageNamed:@"header"]; 
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300, 44)]; 
    imgView.image = img; 

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 44)]; 

    [view addSubview:imgView]; 
    [view addSubview:label]; 

    return view; 
} 

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    int aSection = [[self.sectionsToDisplay objectAtIndex:section] integerValue]; 
    return [self.groupHeadings objectAtIndex:aSection]; 
} 

我的TableView代碼:

tableViewResult = [[UITableView alloc] initWithFrame:mainView.frame style:UITableViewStyleGrouped]; 

tableViewResult.separatorColor = [UIColor clearColor]; 
[mainView addSubview:tableViewResult]; 

我的任何數據加載到表之前設置的另一種方法的委託和數據源,因爲我首先做一個網絡請求,即當Web請求做我做的:

tableViewResult.delegate = self; 
tableViewResult.dataSource = self; 
[tableViewResult reloadData]; 

一切正常如預期的那樣,除了最上面部分的標題,並且僅在iPad上。

任何想法可能導致此行爲?

+0

你如何創建的TableView,從界面生成器或代碼?標題的高度是多少?你可以上傳截圖嗎? –

+0

我從代碼構建它,會上傳截圖。 – Armand

+0

您是否寫過節的方法? – Mangesh

回答

0

什麼固定的問題是改變這一功能:

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    int aSection = [[self.sectionsToDisplay objectAtIndex:section] integerValue]; 
    if([[self.groupHeadings objectAtIndex:aSection] isEqualToString:@""]) 
     return nil; 
    return [self.groupHeadings objectAtIndex:aSection]; 
} 
相關問題