在我的表格 View 中,我有三个部分,其中第一部分包含图像单元格,第二部分包含段控制单元格,第三部分包含一些标签单元格。
我正在做的是当用户向上滚动表格 View 时,所有内容都会向上滚动,但段控制单元格的位置将固定在屏幕的上边缘。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSIndexPath *indexPathOfCurrentHeaderCell = [NSIndexPath indexPathForRow:0 inSection:0] ;
UITableViewCell *headerCell = [self.tableView cellForRowAtIndexPath:indexPathOfCurrentHeaderCell];
if (headerCell.frame.origin.y < self.tableView.contentOffset.y)
{
self.cellHead.hidden = NO;
self.cellHead.frame = CGRectMake(0, self.tableView.contentOffset.y, self.cellHead.frame.size.width, self.cellHead.frame.size.height);
}
[self.tableView bringSubviewToFront:self.cellHead];
}
但是函数 bringSubviewToFront: 在这里似乎不起作用(第二部分将被第三部分覆盖)。我认为这是因为单元格不是表格 View 的 subview 。
想把段控单元拉到前面怎么办?
最佳答案
您应该将段控件添加为标题而不是表格 View 中的单元格,使用
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
然后,您将有 2 个部分,
1. image cell
2. segment control as header, labels as the cells
关于ios - 如何将某个单元格放在前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22975551/