2011-03-16 57 views
3

我已經確保了我的細胞的自動大小掩膜允許靈活的寬度,但是當設備被旋轉時,細胞沒有被調整大小。使用IB大小調整構建的自定義UITableViewCell?

我也驗證了tableview被調整大小,問題是直接與單元格有關。

這是我用來創建細胞代碼:

if (cell == nil) { 
     // Load the top-level objects from the custom cell XIB. 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MetaTableViewCell" owner:self options:nil]; 
     // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain). 
     cell = [topLevelObjects objectAtIndex:0]; 
    } 

有人能想到的可能是什麼問題?

是否使用IB創建的單元格不會調整大小?

+0

您確定它是沒有被調整大小的單元格本身;而不是單元格中的某些內容? – GendoIkari 2011-03-16 21:39:58

+0

我已經通過刪除單元格中的所有內容並顯示它進行了測試。它仍然不會調整大小。 – Zebs 2011-03-16 21:50:49

+0

如果細胞中沒有任何東西,你怎麼知道細胞在哪裏?這些是分組還是樸素的風格?就我所知,你永遠無法控制表格單元格的寬度;它總是隻是無論表本身 – GendoIkari 2011-03-16 21:53:39

回答

1

如果其未調整大小的單元格的高度,建議您在旋轉後修改UITableView委託方法。

-

(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if(condition)// has rotation taken place 
    // new height 
    else 
    // old height 
    } 

請確保您撥打[tableView reloadData];旋轉時有發生。

0

如果我理解你的問題,你想改變UITableViewCells的高度,對吧?嘗試添加此行在您的TableView的代表:

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

我有同樣的問題。如果您在IB中設置尺寸,則可以在其中放置更多材料,但在加載時仍然會要求代表提供高度。如果你的委託沒有實現這個方法,它只會採用默認的高度。

相關問題