Changing Constraints of UITableViewCell, not affecting TableViewCell height in TableView - ios

I am changing the constraint for Cell, But the height of the Cell remains same till deque, after dequeuing it gives correct result.
Any idea how can we reload the cell if the cell constraints are manipulated?
Using Rxswift for Cell View Model, but TableView is in Objc.
Thanks

It is always nice to share your code.
How are you changing the height of your cell? Are you using the heightForRowAtIndexPath delegate.
For changes to appear, I use this code.
[self.tableView beginUpdates];
[self.tableView endUpdates];
If this does not work for you, please share your code and I would update my answer accordingly.

Related

iOS11 UITableview reloadRowsAtIndexPaths glitch

Can anyone help me understand or solve this UITableView glitch in iOS11. I have managed to reproduce my issue in a fairly simple test case.
https://github.com/trapper-/iOS11-tableview-glitch
When reloading cells near the bottom of a tableview the reloaded cell will start to scroll weirdly and other cells start to move and hop around.
It gets much worse when reloading multiple cells, but I didn't want to complicate this simple example.
Edit: This issue only occurs in iOS11, works fine in iOS10 & iOS12. So
you need to download the iOS11 simulator to test this in Xcode 10
This should help:
[UIView performWithoutAnimation:^{
[tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
If I use like this, its working.
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
Try providing estimatedRowHeight to 0 to table view on viewDidLoad. It works for me.
Please try setting you're table view estimatedRowHeight (in the viewDidLoad method):
self.tableView.estimatedRowHeight = 100;
The tableView.rowHeight is set to UITableViewAutomaticDimension by default but you need to set the estimatedRowHeight
From apple - "To enable self-sizing table view cells, you must set the table view’s rowHeight property to UITableViewAutomaticDimension. You must also assign a value to the estimatedRowHeight property. As soon as both of these properties are set, the system uses Auto Layout to calculate the row’s actual height."
You can check out:
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.html

reloadRowsAtIndexPaths updates the contentOffset Of the table view

I am trying to reload a particular row from the tableview but the contentOffset of the tableview is reset to (0, 0) after the reload. I tried to add [tableview beginUpdates] and [tableview endUpdates] around the reloadRowsAtIndexPaths but didn't change the behavior.
The question was asked over here Calling reloadRowsAtIndexPaths removes tableView contentOffset but it did not solve the problem. I am pretty sure that animation has nothing to do with this behavior. I am not sure how to maintain the content Offset of the tableview while still reloading the tableview row.
[tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
I'm guessing you've implemented tableView:estimatedHeightForRowAtIndexPath: and have it returning 0.
After reloadRowsAtIndexPaths:withRowAnimation:, the tableView determines its offset using the estimated heights given in tableView:estimatedHeightForRowAtIndexPath:. So unless the value you return there is accurate, implementing it will cause your tableView's offset to change after the reload. I had a similar problem and fixed it by removing my implementation of tableView:estimatedHeightForRowAtIndexPath:.
Updating the estimatedRowHeight and estimatedSectionHeaderHeight with more accurate values can also help alleviate this issue if you haven't implemented any of the estimated height delegate methods.
You can use the view inspector to find the heights of your cells and headers.

How can I aesthetically resize a UITableview's Cell when I type?

Hi I'm trying to resize a UITableView's UITableViewCell as I type in a TextView in the cell. I want the text to keep flowing but focus on what I"m typing now. This is similar to what you would experience in the Mail App. What is the best way to resize the cell dynamically as I keep typing and entering content?
I'm assuming you are already sizing your cell dynamically.
Whenever the user types a character do this...
[tableView beginUpdates];
[tableView endUpdates];

Dequeued UICollectionViewCell not refreshed

I have an application with a UICollectionView with horizontal scroll of cells (Only one cell is displayed at a time). Each cell hosts a UITableView which displays content (URL links) in each of the UITableViewCell.
The problem is that the first two cells of UICollectionView display the proper content, but starting from the third cell, the contents are displayed from the dequeued cells. The correct content on the dequeued cell's UITableView is only displayed if user scrolls down and then scrolls up to the top.
For example, the contents of the third cell are the content from the first cell.
The cell is a custom UICollectionViewCell that hosts the UITableView. The custom cell implements the UITableViewDataSource, UITableViewDelegate.
I have searched through different forums and sites and found the solution of refresh.
I tried adding the [collectionView reload] to the -cellForItemAtIndexPath: method, but it goes into constant loop. I know that is not the right place, but i do not have any other methods that cause the refresh (only scrolling through the cells loads the next cell's content).
Can somebody please help me to resolve the issue?
You are missing some facts about dequeuing.
When you 3d custom UICollectionViewCell is dequeued, it isn't allocated like when it's displayed for the first time. Instead, your collection view "reuses" 1st cell for displaying 3d. The best moment to clear content in your custom cell class is -(void)prepareForReuse. If you override it and clear it's content, the -cellForItemAtIndexPath: will dequeue "clear" cell which you can further customize.
However, i don't exactly know how to "clear" the tableView, not sure whether it's possible. You have to reloadData on your tableView in -cellForItemAtIndexPath:. Example:
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath
{
MyCVCell *cell = [collectionView dequeueReusableCellWithIdentifier:#"MyCVCell" forIndexPath:indexPath];
cell.arrayOfURLsForDisplay = self.arrayOfArraysOfURLs[indexPath.row];
[cell.tableView reloadData];
return cell;
}
Here i mean you have some arrayOfArraysOfURLs in your viewController and you dislay URLs in your custom cell from some arrayOfURLsForDisplay
I had similar problem, instead of using [cell.tableView reloadData] inside the cellForItemAtIndexPath, I called collectionView.reloadData in the prepareForUse method that is overwritten in your custom UITableviewCell

Dynamic Height UITableViewCell data wrong order

Is it appropriate to call [tableView beginUpdates] and [tableView endUpdates] in cellforRowAtIndexPath?
I am trying to dynamically expand cell heights based on the content within the cell. When I use [tableView beginUpates] and [tableView endUpdates] in cellForRowAtIndexPath, the output looks ok. However, once I start scrolling, data in the cells becomes ordered incorrectly and sometimes the bar separator between table cells disappears.
Should I not be using [tableView beginUpdates] and [tableView endUpdates] for this?
Thanks!
You've got to specify your dynamic cell heights in heightForRowAtIndexPath because the table view wants to know its content size up-front. Any changes you make to the cell's frame in cellForRowAtIndexPath will be overridden by the table view, so what you're attempting won't work.
If your heights are derived from the cell's content, consider using the prototype approach outlined here. Also, if you can use a 3rd party library, check out TLIndexPathTools. It does dynamic cell height for free if your custom cell class implements the TLDynamicSizeView prototype. Try running the Dynamic Height sample project.

Resources