4

This problem does not necessarily occur

Sometimes it disappears when sliding and sometimes does not disappear

more information here

click to show gif

click to show storyboard png

code

HSubjectCell *cell = [tableView dequeueReusableCellWithIdentifier:kSubjectCellIdentifier forIndexPath:indexPath];
_subjectView = cell;
cell.delegate = self;
cell.subject = self.subjectArr[indexPath.section - 3];
return cell;
wtf power
  • 43
  • 1
  • 3
  • No idea what could be causing this - perhaps a constraint issue? Have you tried using the view debugger when the cell disappears to see if it has any useful information on the view hierarchy? – Robotic Cat Dec 17 '16 at 04:28
  • 1
    1.First debug without real data, 2. If u r using table view cell automatic dimension then debug with constant cell height and also debug with removing the cell constraints. – iTamilan Dec 17 '16 at 05:17
  • @RoboticCat [photos](https://photos.google.com/share/AF1QipO9AK-ZIEY941Wis5bDU6J5p25zmbmnwNGTGD0Y-Z2Xyt0qYub9ba1LebMfaM1aew?key=RVNRQjVVYnItQnZ4UXhQWUVvLXFiQkh5TWpzZWpB) – wtf power Dec 19 '16 at 01:58
  • @iTamilan 1. heightForRowAtIndexPath-->return deviceWidth * 0.97 + 46; 2. heightForRowAtIndexPath-->return UITableViewAutomaticDimension; bug no result, the problem persists. I'm sure cell constraints are correct [photos](https://photos.google.com/share/AF1QipO9AK-ZIEY941Wis5bDU6J5p25zmbmnwNGTGD0Y-Z2Xyt0qYub9ba1LebMfaM1aew?key=RVNRQjVVYnItQnZ4UXhQWUVvLXFiQkh5TWpzZWpB) – wtf power Dec 19 '16 at 01:59

1 Answers1

5

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 simple UIView to it (let's say it has an orange background colour), which pins its edges perfectly to each edge of that UITableViewCell's contentView.

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's contentView, you make it go 50.0f over the bottom of the contentView, therefore being outside of the UITableViewCell.

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's contentView a colour that stands out, such as [UIColor orangeColor];. Then you'll better understand how the frames are all relating.

Edwin Finch
  • 913
  • 3
  • 10
  • 24
  • It's alright, I'll try to make it clearer. Unfortunately those photos are showing 404 for me, can you try another way to share them? – Edwin Finch Dec 18 '16 at 17:47
  • [photos](https://photos.google.com/share/AF1QipO9AK-ZIEY941Wis5bDU6J5p25zmbmnwNGTGD0Y-Z2Xyt0qYub9ba1LebMfaM1aew?key=RVNRQjVVYnItQnZ4UXhQWUVvLXFiQkh5TWpzZWpB) – wtf power Dec 19 '16 at 01:57
  • Hmm, that's weird. Is there somewhere in your code where you are modifying the frames or sizes of your cells somehow? As well, does the frame size of your table view match your view controller's/root view's? – Edwin Finch Dec 19 '16 at 03:49
  • Thanks for your tips(_where you are modifying the frames or sizes of your cells_ ), Maybe I know the cause of the problem, `cellForRowAtIndexPath` **many requests** , and `reloadSection` when completed, frames of cells were madified – wtf power Dec 19 '16 at 06:28
  • This is helpful. I add a uiview as separator line of table cell, found it is disappear when scrolling up/down. No I constraint it to bottom anchor of cell, the issue is fixed. `separatorLine.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)` . – Zhou Haibo Dec 18 '20 at 06:11