2010-05-30 45 views
1

我的應用程序中有一個適度不定製的UITableView,它提供了一個網絡遊戲最多6個對等體的陣列。當沒有同齡人發現numberOfRowsInSection是0,所以當它加載了,有表中沒有行:UITableViewCell與0行的高度

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 0; 
} 

麻煩的是,每個單元的高度不調整,以匹配heightForRowAtIndexPath除非numberOfRowsInSection> 0 。我在numberOfRowsInSection的「1」中硬編碼,並且高度按照預期調整。

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

誰能告訴我這是爲什麼?一旦呈現的數據長度超過「0」,表格單元的高度是否會跳到正確的高度?即使行長爲0,我也希望它們是正確的高度。

回答

2

嘗試在UITableView上設置rowHeight屬性。我的猜測是它甚至不會調用heightForRowAtIndexPath,除非該行中實際存在單元格。

(一般來說,順便說一下,如果所有的行都是一樣的高度,你應該使用rowHeight代替heightForRowAtIndexPath - 看到docs。)

+0

哇,我不知道存在。時間進行一些重構。至少很簡單! :) – typeoneerror 2010-05-30 08:58:44

1

工程。只需在viewDidLoad()中添加[self.tableView setRowHeight:XX]即可。