[英]How to bring a certain cell to front
在我的表格视图中,我分为三个部分,其中第一部分包含一个图像单元格,第二部分包含段控制单元格,第三部分包含一些标签单元格。 我正在做的是,当用户向上滚动表格视图时,所有内容都会向上滚动,但是段控制单元的位置将固定在屏幕的上边缘。
- (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:在这里似乎不起作用(第二部分将在第三部分中介绍)。 我认为这是因为单元格不是表视图的子视图。 如果我想将段控制单元拉到最前面,该怎么办?
您应该使用以下方式将细分控件添加为标题,而不是在表视图中添加单元格:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
然后,您将有2个部分,
1. image cell
2. segment control as header, labels as the cells
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.