2011-09-15 44 views
1

編輯:它工作正常,但仍然當表得到負載表頂部和表頭abt 30 pxcls(或1行)之間有一些差距..?只有當表格加載並向下滾動到最後一行時,表格頂部和表格標題之間纔會出現一些間隙?

請幫助....

我滾動它工作正常。所有錶行都滾動,表頭是固定的。 但是,當我滾動到表的末尾它失去了修復的屬性。我的意思是邊界滾動。我想絕對凍結它。在邊界條件下,它會丟失桌面的頂部位置並滑動約20個字節。

//Header Format starting 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return 20.0; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  
{ 
    if (tableView.tableHeaderView) { // header was already created... go away 
     return tableView.tableHeaderView; 
    } 

    CGFloat width = 300.0f; 
    CGRect rectArea = CGRectMake(10.0f, 5.0f, width, 25.0); 

    tableView.tableHeaderView = [[[UIView alloc] initWithFrame:rectArea] autorelease]; 

    //UIColor *orange = [UIColor colorWithRed:(255.0f/255.0f) green:(228.0f/255.0f) blue:0.0f alpha:1.0f]; 

    [tableView.tableHeaderView setBackgroundColor:[UIColor grayColor]]; 

    rectArea = CGRectMake(02.0f, 1.0f, width, 20.0); 
    UILabel *lbl = [[UILabel alloc] initWithFrame:rectArea]; 
    lbl.text = NSLocalizedString(@"Bill Total", @""); 
    lbl.textAlignment = UITextAlignmentLeft; 
    //lbl.font = [UIFont systemFontOfSize:13.0f]; 
    lbl.font = [UIFont fontWithName:@"Courier New" size:14]; 
    lbl.font=[UIFont italicSystemFontOfSize:14]; 
    lbl.textColor = [UIColor blackColor]; 
    lbl.backgroundColor = [UIColor clearColor]; 
    lbl.numberOfLines = 2.0f; 
    lbl.lineBreakMode = UILineBreakModeWordWrap; 
    //[lbl sizeToFit]; 

    [tableView.tableHeaderView addSubview:lbl]; 
    [lbl release]; 

    // self.table.tableHeaderView.layer.cornerRadius = 6.0f; 

    return table.tableHeaderView; 
} 

回答

2

如果我正確理解你的問題,這聽起來像你只需要表不反彈。如果是這樣的話,你所需要做的就是在你的viewDidLoad函數中設置yourTable.bounces = NO;。或者,如果您使用佈局表格的方式取消選中NIB中的「彈跳」選項。

以下是如何解決您在編輯中提到的問題...您需要將以下對tableView.headerView的引用替換爲未傳遞給委託方法的新視圖。

UIView *headerView = [[[UIView alloc] initWithFrame:rectArea] autorelease]; 
    //...  
    [headerView setBackgroundColor:[UIColor grayColor]]; 
    //... 
    [headerView addSubview:lbl]; 
    //... 
    return headerView; 

我試過了,它爲我做了詭計。希望有所幫助。

相關問題