0
我想添加一个自定义的底部边框到我使用UIImageView,我在运行时以编程方式添加到单元格的所有我的tableview单元格。问题在于,当用户滚动时,边框会随机消失。动态添加边框子视图到UITableViewCell
此代码是在我的cellForRowAtIndexPath方法:
UIImageView* border = (UIImageView*)[cell viewWithTag:10];
if (border)
[border removeFromSuperview];
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
NSInteger row = indexPath.row;
if (row != sectionRows - 1) {
UIImageView* border = [[UIImageView alloc] initWithImage:[[ImageManager sharedManager] imageNamed:@"dashed_border"]];
[border setFrame:CGRectMake(10, [self tableView:tableView heightForRowAtIndexPath:indexPath], 290, 1)];
[border setTag:10];
[cell addSubview:border];
[border release];
}
它,如果它存在,删除一个边界子视图,并且如果该行不是最后一行,则在该行的底部插入边界。
我不确定这是否是一种竞争条件,或者是否有某些时候cellForRowAtIndexPath在用户滚动时未被调用。
该节中的行数是否曾经改变? – smparkes 2012-01-28 01:43:17
无论你做什么,你最好不要总是删除边框和重新添加它,这似乎是最常见的情况。相反,只有当它在那里,你才是最后一行。通常情况下,这样简单的事情不会有什么大不了的,但在表格视图单元格中,你不想做任何你不需要的工作。 – smparkes 2012-01-28 01:45:17
不,行数根据集合中的项目数设置。 – James 2012-01-28 01:51:25