2012-02-13 75 views

回答

3

使用表頭視圖。將視圖拖到表格視圖的頂部,它將成爲「表格標題視圖」。

如果您有其他類似的「單元格」基本上是恆定的(可能會打開/關閉),您可以考慮將UITableViewCell對象放在xib中,並從tableView:cellForRowAtIndexPath:委託方法返回它們。還執行tableView:heightForRowAtIndexPath:方法。

兩者都可以具有相同的大致輪廓,如:

-(UITableViewCell*)tableView:(UITableView*)tv cellForRowAtIndexPath:(NSIndexPath*)ip 
{ 
    if (ip.section==0) return headerCell; 
    // ...handle regular cells 
} 

-(CGFloat)tableView:(UITableView*)tv heightForRowAtIndexPath:(NSIndexPath*)ip 
{ 
    if (ip.section==0) return headerCell.frame.size.height; 
    // ...handle regular cells 
    return 44; 
} 
1

要麼使它不是一個單元格(如表格的標題視圖),或實現-[UITableViewDelegate tableView:heightForRowAtIndexPath:]返回不同的高度。您可以使用IB安裝表頭,但更復雜的攻擊方法需要使用代碼。

+0

我站好了!它似乎只是拖放(tableHeaderView不是一個插座),但它絕對有可能。謝謝,mvds! – 2012-02-13 23:22:39

0

這裏是一個片段,您可以use.It是表格的標題視圖...

- (UIView的*)的tableView :(UITableView的*)的tableView viewForHeaderInSection:(NSInteger的)部分{

if(section==0){ UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableview.frame.size.width, 44)]; 
[view setBackgroundColor:[UIColor redColor]]; UILabel 
*label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)]; 
[label setText:@"Hello!!"]; 
[label setBackgroundColor:[UIColor clearColor]]; 
[view addSubview:label]; return view; 
}return nil; 

} 在這裏你可以設置tableViewHeaderSection高度。

  • (CGFloat的)的tableView:(UITableView的*)的tableView heightForHeaderInSection:(NSInteger的)部分{

    返回100; }