2014-10-18 60 views
0

我已經創建了4個不同的imageViews單元,我創建了動態約束,因此它們將改變寬度和高度等於設備大小,但由於單元格不是動態的, t改變imageView的高度。因此,我想將單元格高度設置爲與圖像寬度相等,因此圖像始終具有相同的寬度和高度。單元格高度等於圖像寬度

在heightForRowAtIndexPath,我試圖返回以下,但是這是給我的錯誤:(LLDB)

let cell = tableView.dequeueReusableCellWithIdentifier("ImageViewCell", forIndexPath: indexPath) as ImageViewCell 

return cell.image1.frame.width 

我怎樣才能做到這一點?

回答

0

你不能在heightForRowAtIndexPath內調用單元對象,因爲它創建了無限循環,因爲cellForRowAtIndexPath調用了heightForRowAtIndexPath。其次,調整width使用約束 作爲函數名稱清楚地表明它是爲高度。

如果您知道有關控制的高度,然後用這個

return 90.0 //its optional if height is fixed 

其他
添加constraintstopbottomleftrightwidthheight約束,並使用> =條件身高限制。

0

我認爲你需要使用Tableview的委託來設置它的單元格高度。也許你可以嘗試事端這樣的:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    switch (indexPath.row) { 
    case 0: 
     return image.frame.size.width; 
     break; 
    case 1: 
     return image.frame.size.width; 
     break; 
    default: 
     return 44; 
     break; 
    } 
} 

我認爲你需要從數據源獲取的UIimage大小。不是來自你的手機。

相關問題