我有一個不同高度的表視圖,如在heightForRowAtIndexPath中定義的。出於某種非常奇怪的原因,圖像根據高度向右「縮進」;如果高度足夠低,則圖像粘貼到單元的左側,但隨着高度增加,與其他行相比,所述單元的圖像向右移動。當改變heightForForWowAtIndexPath在UITableViewCell中時,圖像「移動」
這樣做的結果是一個非常貧窮的尋找列表,圖像floppily取決於每個單排的高度在Z字形佈局。
問題是由這個簡單的例子表明:
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return (indexPath.row+1) * 50;
}
每個小區設置(簡體)作爲具有 「字幕」 風格的單元格:
// ...
cell.textLabel.text = @"foo";
cell.detailTextLabel.text = @"bar";
cell.imageView.backgroundColor = [UIColor redColor]; // for debugging; i have images with transparent bg
cell.imageView.image = anImageThatIs55x50pixelsBig;
return cell;
任何想法?我的頭從牆上流下了愛情。
編輯:上傳了一個顯示這個的屏幕。 「圖像」只是屏幕上一個很小的區域的截圖,這使得它看起來有點不可思議,但你得到的圖片我敢肯定:http://img28.imageshack.us/img28/549/screenshot20100311at172.png
出於測試目的,您可以創建UIImageView,然後使用單元格的addSubview方法,如果這最終是您的解決方案,您應該繼承UITableViewCell的子類。 – 2010-03-13 02:42:30
這樣做了!非常感謝你的想法!在某些時候,我肯定應該製作自己的單元格,但現在,下面的技巧(在cellForRowAtIndexPath中): UIImageView * iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,[self tableView:tableView heightForRowAtIndexPath: indexPath]/2-26,55,55)]; cell.indentationLevel = 5; //不在圖像中獲取文本 iv.image = theImage; [cell addSubview:iv]; [iv release]; – Kalle 2010-03-13 16:39:27