2010-05-11 12 views

回答

1

您將不得不爲這個特定的單元格創建一個自定義單元格,但是它會被立即執行一次,這要感謝reusableCells。例如:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    static NSString *CellIdentifier = @"TableCell"; 
    static NSString *ImageIdentifier = @"ImageCell"; 
    UITableViewCell *cell; 

    if (!(indexPath.row % 3)) 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:ImageIdentifier]; 
     if (cell == nil) 
     { 
      cell = [[[MyCustomCell alloc] initWithDelegate:self reuseIdentifier:(NSString *)ImageIdentifier] autorelease]; 
     }   
    } 
    else 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:ImageIdentifier]; 
     if (cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithDelegate:self reuseIdentifier:(NSString *)ImageIdentifier] autorelease]; 
     } 

     // customization of your rows here (title, ...) 
    } 

    return cell; 
} 
+0

謝謝你!但是我使用了不同的選項。你完全正確。沒有問題與你的代碼。再次感謝。 – 2010-05-11 11:04:07

0

我不相信這是可能的,因爲你的圖像對於標準的UITableViewCell來說太大了。您需要製作自定義單元格,然後在cellForRowAtIndex方法中加載適當的單元格。不要忘記在代碼/ IB中設置適當的cellIdentifiers。

也許你可以添加一個UIImageView作爲標準單元的contentView的子視圖,但這聽起來不像是我最好的解決方案。

+0

其實我知道這是可能的,因爲在泰伯維的 - (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath 在這種方法,通過編寫這些代碼,我們可以做到這一點,但我只是想設置圖片 cell.image = [UIImage imageNamed:@「abc.png」]; 但是,如果您爲圖像設置單元格框架,則此代碼無法設置單元格的實際圖像大小,請告訴我。並感謝您的回覆。 – 2010-05-11 07:19:34

+0

我不相信你可以改變標準UITableViewCell的幀大小。 Thomas Joulin的代碼示例是最好的選擇。 – 2010-05-11 07:26:02

0

只是要足夠高度的小區,其相應的委託方法,然後添加您的圖像視圖作爲一個子視圖到小區的物業contentView

相關問題