iphone - commitEditingStyle 的透明背景

标签 iphone objective-c ios uitableview

当滑动第三个单元格后出现删除按钮时,背景被剪裁。我怎样才能解决这个问题?这是制作自定义单元格时的代码。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    
      (NSIndexPath *)indexPath
     {
         static NSString *CellIdentifier = @"customCell";

         BookMarksCustomCell *cell = (BookMarksCustomCell *)[tableView  
         dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) {

            NSArray * topLevelObjects = [[NSBundle mainBundle]  
            loadNibNamed:@"BookMarksCustomCell" owner:self options:nil];

        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[UITableViewCell class]])
            {
                cell = (BookMarksCustomCell *)currentObject;
                break;
            }
         }        
    }

    .....more logic stuff.

    //alternating cell background.
    if([indexPath row] % 2 == 0)
        cell.contentView.backgroundColor = [UIColor colorWithRed:234.0/255.0 
        green:234.0/255.0 blue:234.0/255.0 alpha:1.0];

    ......
   }

http://i228.photobucket.com/albums/ee262/romano2717/photo3.png

最佳答案

您的代码正在修改 contentView 的背景颜色细胞的属性。当删除按钮出现时,此 View 会调整大小,因此您需要设置单元格本身的背景颜色(这也是 UIView 子类)。这应该解决它。

此外,为了考虑单元格重用和更改索引,无论当前单元格是偶数还是奇数,您都应该设置背景颜色。始终明确地将颜色设置为某种颜色(即使它是白色),这样当您滚动时,重复使用的单元格就不会产生奇怪的效果。

我也刚刚注意到 UITableViewCell记录此注释:

If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source.



所以,在那儿做吧。

关于iphone - commitEditingStyle 的透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8889416/

相关文章:

ios - 仅使用 iFrame 在 UIWebView 中播放 youtube 视频

ios - 我如何引用 GameScene.swift 文件作为其余游戏关卡的基础?

ios - 快速执行 BOOL Getter 上的 Exc_bad_access

ios - 如何调整 UITabBarItem 的大小?

将文本字段设置为数字键盘时的 ios swift 导致奇怪的错误

iphone - iOS GameCenter 匹配器不工作

ios - 当我收到 Parse 的推送通知时,如何播放声音?

iphone - 如何在 mfmailcomposerview 中关闭键盘

iphone - 将字符串分配给 UITextView

iphone - 为 UItextview 键盘设置动画