gpt4 book ai didi

iphone - commitEditingStyle 的透明背景

转载 作者:行者123 更新时间:2023-12-01 19:23:55 26 4
gpt4 key购买 nike

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

    - (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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com