1. Setting the height of the CollectionView
1.1 Why should I set the height?
CollectionView is in TableView footview inside, TableView can scroll, CollectionView can also scroll we don't want to let CollectionView scroll
1.2 How can I let CollectionView do not scroll?
As long as the contents of the CollectionView not exceed the maximum height of CollectionView can be
1.3 How to set the height of the CollectionView
Calculates the height of the CollectionView content = CollectionView
1.4 How to calculate the height of the CollectionView content
Set CollectionView height = content height (Rowsitemwh + (rows-1) margin)
Total Row Cell height + (total number of rows-1) * Line spacing
1.5 How to calculate the total number of rows
Calculate Total Row count: (count-1)/cols + 10,000 Energy Formula remember
(Total number of models-1)/number of cells per row (item) + 1
1.6 Where is the code written?
To calculate the height, we first have to get the total number of the model code written in the dictionary to the model can be a dictionary to the model generally written in the network request a successful callback method inside
and write before you refresh the table.
2. Set the scroll range of the TableView
2.1. Why to set the scroll range
CollectionView the height of the screen, we scroll tableview to see Collectionviewcell found below will bounce back
2.2. Why does it bounce back?
The height of the TableView is determined by the maximum Y value of the last cell or Footview
Footview height is the height of CollectionView, we set the height of the CollectionView is 200
Although the height of the CollectionView is reset, the Tablefooterview height is already set to 200 at 200.
2.3. How do I change the scrolling range?
Use Contentsize to set the maximum Y value of collectionview content as long as the maximum height of the TableView is set.
Modified to find a bug when you leave the current page and return to the time, scroll TableView found will bounce back
2.4. Why is it bouncing back?
TableView scrolling range is set by the system itself, we set the value of the system does not recognize, will not be recorded, only the first time we will be executed
Once again, the system will restore its own recorded scroll range contentsize
2.4. How the system is set contentsize
is determined by the maximum Y value of the last cell or Footview
2.5. How to solve the problem of bouncing back
We re-set the last cell or Footview and the scrolling range will be recalculated.
2.6. Where is the setting?
First we need to get CollectionView's frame after the network request succeeds we will recalculate the height of the CollectionView after the calculation
and write before you refresh the table.
3. Handling of additional lattices
3.1 Why should I deal with it?
The data returned by the server is not necessarily an integer multiple of the number of columns so the last line may only show 1 cells behind and there are a few notches that need to be handled.
3.2 How to deal with it?
If there is a gap, we just need to show the empty cell at the notch location.
3.3 How to show the empty cell
The number of cells is determined by the number of models, and the number of models is determined by the number of elements in the model array (count)
We just need to add the element (object) to the model array.
3.4 Where is the code written?
We're going to get the total number of models. The code is written after the dictionary to the model can be a dictionary to the model generally written in the network request a successful callback method inside
and write before you refresh the table.
4. Handling TableView static cell spacing
What is the result of 4.1 spacing?
Our tableview is a grouping style.
Grouping style TableView: Default spacing for each group we guess spacing is the spacing between groups
4.2 How to verify?
Set the packet spacing to the Zero view interface Verify that our guesses are correct.
and set the spacing to the space we want.
self.tableView.sectionHeaderHeight = 0;
Self.tableView.sectionFooterHeight = 10;
4.3 We find that the spacing between the groups is set, and the first cell has a large gap between the top and the other, how is this pitch caused?
The cell is spaced at the top, only in a static cell.
Guess is the inner margin Contentinset
4.4 How to verify?
Print Contentinset
4.5 Where to print?
Inside the viewdidload, you can't view the control's position size is not set.
We can print it out in Viewdidappear, it's 64, not this pitch.
Guess is the Y value of the cell
4.6 How to verify?
Print the cell's frame
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; NSLog(@"%@",NSStringFromCGRect(cell.frame)); } 我们发现y值为35 ,证明猜测是正确的
4.7 How can I modify the Y-value directly?
Not modifying the Y value of a cell only changes the location of a cell
4.8 How to make the whole cell inside the TableView Move up (down)
Can be done by contentinset
Self.tableView.contentInset = Uiedgeinsetsmake (-25, 0, 0, 0);
4.9 Based on the above settings we found that the system modification Contentinset is based on our original Contentinset class added
Collectionview,tableview details of the process