Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 目标c-提供两个tableview单元格之间的空间_Ios_Objective C - Fatal编程技术网

Ios 目标c-提供两个tableview单元格之间的空间

Ios 目标c-提供两个tableview单元格之间的空间,ios,objective-c,Ios,Objective C,我正在寻找一种在两个UITableViewCell之间添加空间的方法,就像在facebook中一样,并找到了一种解决方案,请检查下面的代码 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ cell.contentView.backgroundColor = [UIColor whiteColor

我正在寻找一种在两个UITableViewCell之间添加空间的方法,就像在facebook中一样,并找到了一种解决方案,请检查下面的代码

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
cell.contentView.backgroundColor = [UIColor whiteColor];
UIView  *whiteRoundedView = [[UIView alloc]initWithFrame:CGRectMake(8, 8, self.view.frame.size.width-18, cell.contentView.frame.size.height - 18)];
CGFloat colors[]={1.0,1.0,1.0,1.0};//cell color white
whiteRoundedView.layer.backgroundColor = CGColorCreate(CGColorSpaceCreateDeviceRGB(), colors);
whiteRoundedView.layer.masksToBounds = false;
whiteRoundedView.layer.cornerRadius = 5.0;
whiteRoundedView.layer.shadowOffset = CGSizeMake(-1, 1);
whiteRoundedView.layer.shadowOpacity = 0.3;
whiteRoundedView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
[cell.contentView addSubview:whiteRoundedView];
[cell.contentView sendSubviewToBack:whiteRoundedView];}
这段代码给了我想要的输出,但问题是 当我滚动tablview时,它会一次又一次地调用并使我的应用程序变慢 当我向下滚动时,阴影也在不断增加
有人能帮我解决这个问题吗?

只需在单元格中添加一个视图,与单元格相比,高度减少20像素,并将y位置设置为10


将单元格背景色设置为清晰,并将视图颜色设置为单元格背景色

只需在单元格中添加一个视图,与单元格相比,高度减少20像素,并将y位置设置为10


将单元格背景色设置为“清除”,并在重新使用单元格背景色时设置“视图颜色”

TableViewCells-如果有很多行,它们会一次又一次地重复使用。每次调用
willDisplayCell:
时,您都在添加另一个
whiteRoundedView
。因此,在您滚动一点并且一个单元格被重复使用了10次之后,您已经添加了10个子视图。滚动一段时间,现在您已经添加了几十个子视图。你每排都是这样做的

您可以:

a) 检查添加的子视图是否存在,并且仅在第一次添加时添加,或者


b) 您可以创建一个自定义的
UITableViewCell
并根据需要对其进行格式化(更好的选择)。

TableViewCell被重用-如果您有很多行,它们会被一次又一次地重用。每次调用
willDisplayCell:
时,您都在添加另一个
whiteRoundedView
。因此,在您滚动一点并且一个单元格被重复使用了10次之后,您已经添加了10个子视图。滚动一段时间,现在您已经添加了几十个子视图。你每排都是这样做的

您可以:

a) 检查添加的子视图是否存在,并且仅在第一次添加时添加,或者


b) 您可以创建自定义的
UITableViewCell
并根据需要对其进行格式化(更好的选择)。

您可以在UITableViewCell的底部添加UIView,这不会影响性能。选中此项:您可以在UITableViewCell的底部添加UIView,这不会影响性能。选中此项: