This problem does not necessarily occur
Sometimes it disappears when sliding and sometimes does not disappear
more information here
code
HSubjectCell *cell = [tableView dequeueReusableCellWithIdentifier:kSubjectCellIdentifier forIndexPath:indexPath];
_subjectView = cell;
cell.delegate = self;
cell.subject = self.subjectArr[indexPath.section - 3];
return cell;
Table views "hide" subviews the instant that cell's frame go out of view of the scroll view.
An simple example on how table views work
Let's say you define your row to have a height of
100.0f
. You add a simpleUIView
to it (let's say it has an orange background colour), which pins its edges perfectly to each edge of thatUITableViewCell
'scontentView
.When you scroll that view up/down far enough so the
100.0f
height is above/below the scroll view's frame, that row is essentially hidden. This is to make the table view snappy and efficient.What you are experiencing
Let's use the previous example, though instead of pinning the bottom of the subview to the bottom of the
UITableViewCell
'scontentView
, you make it go50.0f
over the bottom of thecontentView
, therefore being outside of theUITableViewCell
.You'll notice, if you scroll the orange
UIView
so it goes towards the top, that it disappears even though there is still some orange showing on the screen.But why is this happening?
Because the subview you added does not fit within the
UITableViewCell
, when that cell scrolls out of view (based on its frame), it "disappears". Along with it disappearing, your subviews will too.How do I fix this?
Ensure that all of your subviews are within the frame of the
UITableViewCell
which it is added to.A simple way to see these bounds making the background colour of your
UITableViewCell
'scontentView
a colour that stands out, such as[UIColor orangeColor];
. Then you'll better understand how the frames are all relating.