https://github.com/kittenyang/kyselfsizingpushfixcategory
A UITableView Category for fixing the bug of 'Self-Sizing-Cell' when push to next ViewController the tableView position will change.
https://github.com/kittenyang/kyselfsizingpushfixcategory
Last synced: 2 months ago
JSON representation
A UITableView Category for fixing the bug of 'Self-Sizing-Cell' when push to next ViewController the tableView position will change.
- Host: GitHub
- URL: https://github.com/kittenyang/kyselfsizingpushfixcategory
- Owner: KittenYang
- License: mit
- Created: 2015-04-20T11:38:45.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-10T11:02:17.000Z (almost 10 years ago)
- Last Synced: 2025-03-20T13:26:46.001Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 195 KB
- Stars: 29
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()


A UITableView Category for fixing the bug of 'Self-Sizing-Cell' when push to next ViewController the tableView position will change.
#Installation
`pod 'UITableViewController+KYSelfSizingPushFix', '~> 1.0.0'`
##How to use
###Three Steps:
**1.Add code in `- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath`**
```objective-c
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {...
if (![self ky_isEstimatedRowHeightInCache:indexPath]) {
CGSize cellSize = [cell systemLayoutSizeFittingSize:CGSizeMake(self.view.frame.size.width, 0) withHorizontalFittingPriority:1000.0 verticalFittingPriority:50.0];
[self ky_putEstimatedCellHeightToCache:indexPath height:cellSize.height];
}
...}
```**2.Implement `estimatedHeightForRowAtIndexPath:`:**
```objective-c
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self ky_getEstimatedCellHeightFromCache:indexPath defaultHeight:250.0f];
}
```**3.Remember to use` [self ky_tableViewReloadData];` rather than `[self.tableView reloadData];`**
##*You're done!*