2012-05-15 55 views
0

下面是我使用的設置表視圖高度一些(簡體)測試代碼:設置UITableView的框架高度 - 顯示的行數不正確

tableView.frame = CGRectMake(tableView.frame.origin.x, 
          tableView.frame.origin.y, 
          tableView.frame.size.width, 
          88); 

我有44點的默認行高。但是,該框架只顯示1行。如果我將高度更改爲132,則顯示2行。

我希望看到2行,如果我使用88的高度。我錯過了什麼。

+0

顯示哪一行沒有最頂層?第一行?還是第二? – ZhangChn

回答

0

使用喜歡 -

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 44.0; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 2; 
} 

附: - 我已經硬編碼了,假設你只需要兩行高度爲44的每行。如果您有分段表格視圖或任何其他自定義實施,您可以自定義此項。

0

所以,擺弄tableView.frame和tableView contentSize後,其中沒有一個工作,解決方案是簡單地扔掉XIB中的tableview並從代碼中執行。

例如

tView = [[UITableView alloc] initWithFrame:CGRectMake(10, 20, 200, 200) style:UITableViewStylePlain]; 
tView.rowHeight = 40.0; 
tView.delegate = self; 
tView.dataSource = self; 
[self.view addSubview:tView];