2012-03-22 29 views
0

如何在tableView中的2個部分之間添加空格。在tableview中添加部分和頁腳視圖 - 初學者

一旦添加以下代碼在

titleForHeaderInSection

if (section==0) 
return @"sec 1"; 
else return @"sec 2"; 

然後,以下

viewForFooterInsection

vi = [[UIView alloc]initWithFrame:CGRectMake(0,0,300,100) ]; 
la = [[UILabel alloc] initWithFrame:CGRectMake(0,0,300,50)]; 
[email protected]"............long text.."; 

[vi addSubView:la]; 

return vi; 

當我將標籤高度設置爲30時,它顯示1/2的文本。因此,我需要增加標籤的高度。然後當我增加高度的第二節標題重疊。我該如何解決這個問題?

回答

1

你在你的tableview委託給指定頁腳的高度,如:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    // Switch here if you like different heights for footers 
    return 50.0f; 
} 
1

答案在於tableView的風格。你看到的風格是UITableViewStylePlain,其中部分不分開。你在找什麼是。這可以在兩個地方給出。

如果要創建一個tableView,使用它的初始化

UITableView *tableView=[[UITableView alloc] initWithFrame:someRect style:UITableViewStyleGrouped]; 

或者,如果你正在創建一個UITableViewController

UITableViewController *tbvc=[[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];