iOS8 UITableView and Cell - Autolayout Height - Shift / Vertical offset bug on touch and perform segue - ios

I have an annoying problem with my tableView when i touch a cell which contain an autolayout label (description of the image). The autolayout works well, but, just when i touch the cell before the segue, a cell shifting movement appears (down or up and never the same height).
Don't understand why and this problem is random , I feel it rather happens when a cell is close to appear at the top or bottom.
Here a video of the problem on touch / click on the cell and transition to an another view.
http://youtu.be/kJALa8PhD-U
Image : http://i.stack.imgur.com/uWzDr.png
Reminds something to someone ?
On IOS8 - Swift, Same problem on my iPhone.
Thanks!

Likely what is happening is that because you are using auto layout to get a dynamic height tableviewcell, and iOS is not properly calculating the height of your cells during the segue. Using either the estimatedHeightForRowAtIndexPath delegate callback (if you have varying heights) or the estimatedRowHeight would be my guess at how to fix this.
Doing this should get you two benefits, firstly your views should stop flickering during the segue. Secondly, iOS will not have to look at all of your tableview cells to determine the height of it's scroll indicator (which is good for performance).

Related

Only first collectionViewCell reacts to user interactions

The setup
I have a rather complex view hierarchy which made me do terrible things with tableViews and collectionViews. Right now I'm having a regular grouped TableView with custom TableCells. TableCell itself contains a couple of views and a Collection View. The height of the table cell is calculated based on number of items in the data source. On its creation table cell creates a collection view with a calculated size to fit necessary data.
-- UITableView
---- UITableViewCell
------ UICollectionView
--------- UICollectionViewCell
The problem
I've encountered unusual problem with a custom collectionViewCell. I have a vertical single-column collectionView with dynamic amount of cells. Ideally tapping on the cell should call didSelectItemAt. The cell also has three buttons. Tapping on the button should trigger some action. All of the desired functions work only for a first cell. The rest of the cells are not responsive to any actions.
Things that look strange
By default the scrolling of a collectionView inside of the tableViewCell is disabled because it basically fits all the content based on calculated height and doesn't require scrolling. (Also I don't want it to interfere with tableView scrolling logic).
First
I've tried to hardcode some value for the height of collectionView and enable scrolling. What happened is a mystery for me.
Let's say that calculated height required for the collectionView to show all the content without scrolling is 740. When I manually set it to be 280 (this is enough for exactly 2 cells to fit) and enabled scrolling my first cell were still working, but also when I scrolled collection just a little bit my second cell started to act normally as well. When I scrolled back to the top of the collectionView it was disabled once again.
So it looks like when the scrolling is enabled and will actually occur because of insufficient height to fit the content, cells behave as they should. As soon as I set height of the collectionView to be enough to fit its content, things go wrong.
Second
In some cases I can actually tap on the second cell and it will call the delegate. But the weird thing is it works when I tap in the top area of the cell, like 10pts from the top. The other areas of the cell are unresponsive so are the rest of the cells in the collection.
The working delegates and buttons with enabled scrolling forces to think that this has nothing to do with delayed or canceled touches. The frame for collectionView and height of the table cell are calculated properly as well.
xCode 8.3, iOS9+
As it turned out when I was creating my tableViewCell, I hardcoded the height of the collection to value of 214. The reason for that is very simple. I create a cell programmatically and with tableViewCells created programmatically the height of the cell is always 44. When you override init(style: UITableViewCellStyle, reuseIdentifier: String?)
You need to either hardcore the height, or update it in cellForRowAtIndexPath. Even though I updated collection frame when it was filled with data, the container view of this collection wasn't updated resulting in some sort of clipping area for user interactions.

Custom tableview scroll iOS

I need to show three/ four UI buttons and levels, two image views in a custom cell but there is a condition on the basis of that I need to hide an imageView and when it will be hidden, I need to decrease tableview size and buttons which are below of that image view that will move upward.
For that I am giving required conditions in
heightForRowAtIndexPath
and returning cells height accordingly and in tableview
CellForRowAtIndexPath
method I am hiding imageView and setting buttons positions which are below of that imageView.
The problem is that:
1) TableView is not scrolling smoothly
2) Initially at the time of scrolling down everything is working but when I
move upward then image is resizing and changing its shape. To solve that I have used AutoLayout but still it is not working.
I need your expert advice.
Thanks in advance.

Adjusting the UiTableview hight in IB so the the table its able to scroll all the rows

I have a UITableView that is cutting off the last row and a half. I assume this is due to the face that I am using a navigation controller. What I can't figure out is how to adjust the height of the TableView so that it works on both iPhone 4 and 5's. If I adjust the height in IB to fit the iPhone 4, I have a large gap on the bottom of the iPhone 5. I would think there is some automatic way of doing this, but nothing I am trying seems to be working.
Auto Layout - Official Guide...
Also, if you're using a UITableViewController on the storyboard, this will solve your problem (with or without navigation controller, which is unrelated). If you're using a UITableView on a regular UIViewController, however, the best answer is auto-layout.

How can I make UITableView less sensitive to vertical scrolling?

I have table view that has more than 10 rows and inside each row I'm placing a hortizontally-scrolling scrollview (you can thumb through images much like in Coverflow).
The problem is that UITableView is too sensitive to vertical scrolling. When I'm trying to scroll left and right in a particular scrollview (inside of any cell), the table view starts scrolling up or down once it detects even the slightest movement of my finger upon the y-axis.
Is there a way I can change this and set a higher vertical-scroll threshold for the table view?
Here's a couple suggestions. Try them and see how they feel.
Suggestion 1
When you dequeue your tableViewCells, try calling this:
[tableView.panGestureRecognizer requireGestureRecognizerToFail:cell.scrollView.panGestureRecognizer];
Suggestion 2
Try setting this on your tableView:
self.tableView.delaysContentTouches = NO;
That property defaults to YES. It delays touches to the content of the table view cells by a fraction of a second, to help it recognize the difference between a tap and a drag.

Anchor a UIButton to the bottom of a UITableViewController's view

I have the following requirement. When a UITableViewController's view is displayed, there are a variable number of rows. Underneath the rows, a button should be displayed.
When the number of rows is small, the button should be anchored to the bottom of the view.
When the number of rows is larger, the delete button should be placed immediately after the last row.
In other words:
And not:
My best attempt at this so far has involved setting a tableFooterView and trying to update its height using the contentSize of the UITableView, but I am running into all sorts of problems. I might continue down this path and ask for some help, but first I want to know if anyone has alternative (better) solutions.
The result must play nicely with a double-sized status bar (during a call for example) and I am targeting iOS 6.0. I am not using interface builder.
One possible solution to achieve this effect might have to use two different solutions.
If the amount of rows means that the button will be off the screen then use the footerView like you have been doing.
If the amount of rows means that the button will not be off screen then
Add the button to the tableView
Implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView and update the frame of the button to be offset from the bottom.
The offset from the bottom might follow some logic like this
yOffset = CGRectGetHeight(tableView.frame) - (CGRectGetHeight(button.frame) + somePadding)
yOffset += tableView.contentOffset.y
This would mean that the button still moves up and down with the scrolling but you don't have to mess with the footerView height
Keep both the table view and a button inside scroll view. Keep the button at the bottom of the scrollview. For proper scrolling to work you might want to set the scrollEnabled property of the scroll views. For more details on that check this up
Scrolling a UITableView inside a UIScrollView
EDIT:
yourView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin ;
Check the accepted answer for this question for more details on implimenting struts and springs using code:
UIView autoresizingMask - Interface Builder to Code - Programmatically create struts and springs - Swift or Objective-C

Resources