![](/img/trans.png)
[英]Scale table view cell height proportionally for all screens using autolayout
[英]Give 0 height to table view cell using autolayout
我的數據源數組中有一些虛擬對象。
我不想在屏幕上顯示它們。 我也無法從數據源陣列中刪除它們。
我正在使用適當的約束來獲取動態像元高度。
有沒有一種方法可以使用AutoLayout
為那些虛擬對象顯示高度為0的單元格?
而不是使像元高度= 0 ,您應該考慮如何不顯示該像元 。
如果沒有偽數據就無法復制數據源(因為可能太大了?)
順便說一下,這是最簡單的方法。
然后,您應該構建一個函數,該函數可以在給定索引的情況下為您提供正確的數據。
例如:
如果您有[data1, dummy, data2, dummy, data3, data4]
如果您要求數據源的第二個元素,它應該響應data2
如果您要求數據源的第二個元素,它應該響應data4
當然,您還需要一個函數,該函數可為您提供正確的數據源length
,而不包含所有虛擬數據。
然后只需在適當的地方使用此功能(例如):
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return numberOfActualDataItems(datasource)
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = //Obtain your reusable cell
let item = actualDataItemIndex(indexPath.row)
//configureCell will be the function were you place your data to view
self.configureCell(cell, item)
return cell
}
到目前為止,盡管我不想覆蓋heightForRowAtIndexPath :(
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
SomeObjectClass *object = [dataSourceArray objectAtIndex:indexPath.row];
if (object.objectType == DummyDataType) {
return 0;
}
return UITableViewAutomaticDimension;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.