2
我想設置2個完全不同的外觀(和內容)的單元格。 (一個選中,一個未選中)。UITableView單元格:selectedBackgroundView而不顯示backgroundView
此代碼有效,但是,因爲選定單元格的圖像是50%透明的,我可以在底部看到BackgroundView。
很明顯,selectedBackgroundView提供了一種很好的方式來填充單元格,並且元素僅在選中時可見。難道還有比BackgroundView來填充單元的另一個位置,位置怎麼也不會出現在selectedBackgroundView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"hello";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
UIImage *image = [UIImage imageNamed:@"listview_btn.png"];
UIImage *imageThumb = [UIImage imageNamed:@"01_thumb.jpg"];
UIImageView* imageView = [[UIImageView alloc] initWithImage:imageThumb];
[imageView setFrame:CGRectMake(0, 0, 50, 67)];
[cell setBackgroundView:[[UIImageView alloc]initWithImage:image] ];
[cell.backgroundView addSubview:imageView];
UIImage *imageSel = [UIImage imageNamed:@"listview_btn_on.png"];
UIImage *imageThumbSel = [UIImage imageNamed:@"01_thumb_Sel.jpg"];
UIImageView* imageViewSel = [[UIImageView alloc] initWithImage:imageThumbSel];
[imageViewSel setFrame:CGRectMake(110, 0, 50, 67)];
[cell setSelectedBackgroundView:[[UIImageView alloc]initWithImage:imageSel] ];
[cell.selectedBackgroundView addSubview:imageViewSel];
我花了一次點擊來修復你的代碼格式。也許你應該在下次點擊。爲此,請選擇您插入到問題中的所有代碼,然後按下「{}」按鈕。它會添加適當的降價縮減,所以你的代碼是可讀的,並獲得很好的配色方案:-) – 2012-04-04 02:55:21
當然,它是[Xcode](http://stackoverflow.com/a/5725282/457406)而不是xCode。 Xcode不是iPhone。 Xcode只是一個IDE,它是編寫代碼的工具。如果你的問題不是關於IDE本身的(例如「如何在Xcode中打開行號?」,請不要使用標籤 – 2012-04-04 02:59:09
這個問題沒有答案?(感謝Matthias的更正) – Franck 2012-04-07 12:57:32