How do I speed up tap handling on a complex UITableView - ios

I have an app with a TableView which is contained inside a ScrollView (horizontal pagination).
In each TableView is a custom TableViewCell which has a number of views.
To handle a singular tap on an area within the cell, I add a UITapGestureRecogniser to views within the cell.
Rendering performance is fine. But when I tap, I notice a sizeable delay from the point of tapping, to the point where the selector is called (i.e. I believe most of the time is being spent inside UIKit doing hitTests and finding out which element responds to what).
Is there a way to make this faster? What should I be looking out for that may be causing this problem?

You could try adding a single tap recognizer to a transparent view that fills the cells contentView, add it last so it's front most in the subViews array, then have it to the hit test for just the views of interest.
That said it would seem the delay comes from some other interaction.

Related

UITableView do not respond some touches while scrolling

When tableView is scrolling with high speed, and user tries to stop it by touch, tableView keeps scrolling. And user can stop scrolling tableView only after two or three touches. If speed of tableView scrolling is low, tableView respond touches well.
The tableView displays cells with a lot of subviews, and I localized problem on one view.
If I set problemView.userInteractionEnabled = NO, scrolling works well. To set userInteractionEnabled = NO for all subviews of problemView but not for problemView, do not help.
Here image of diplaying cell, the problemView is view with red frame.
Could somebody to give an advice, how to solve the problem?
There are several possibilities:
Your custom view, or one of its superviews, has userInteractionEnabled set to NO.
There is another view on top of your custom view, or on top of the table view within the custom view.
The custom view that the table view is inside is smaller than the table view (with clipsToBounds=NO, a subview that extends beyond the bounds of its parent can be seen but not normally interacted with). Or the same for another view in the stack.
The custom view (or one of its superviews) overrides pointInside:withEvent: or hitTest:withEvent: incorrectly.
It might be that it thinks you are editing it in some way. Try allowsSelectionDuringEditing = YES. Here is more information with using the UITableView.
If you are using NSTimer inside the UITableViewCell then I have experienced anomalous actions as you have discussed. In such case you need to replace implicitly scheduled timer with explicitly scheduled timer.
For me the problem was that having userInteractionEnabled = true with a click handler on subviews in the cell broke the scrolling. Not sure why this is the case though. I solved this in my case by using didSelectRowAt on the tableview instead of having custom click handlers on the subviews. Then both the scrolling and the click handling worked as I wanted to.

How to drag a row between other rows in UITableView or UICollectionView

I am trying to implement the view shown in the animation below:
I found a great control called TGLStackedViewController which does almost what I need. The way it performs the moving is by taking a snapshot of the card you want to move and adding it as a subview to the collectionView, while hiding the original card. When dragging has stopped the movable view is removed and the original card is made visible again.
This works well, but doesn't produce the result I want since the movable view covers all cards. I wish for the card being moved to always be between the two cells above and below, just like in the animation. But I am not sure how to do this since all items are on the same level. I would really like to avoid making a completely custom view control and if possible do this with either UICollectionView or UITableView.

Adding subview to UICollectionView - disables scrolling

I want to add a subview to a UICollectionView in order to make a left panel that scrolls with the collectionview.
Using
[self.collectionView addSubview:myView]
all touches become disabled and I can no longer scroll the view. I've read that adding a subview to a collectionView like this is bad practice.. is this true? Why does it disable touches from reaching the collectionView event when
userInteractionEnabled = NO
I'm trying to do this: imgur link by grabbing the frame position of the first cell in each section, and adding a dot with to myView with the same y value.
Thanks for any help!
Adding subviews using the addSubview: method to a UICollectionView is very bad practice. It can cause a lot of different problems in the normal behaviour of the CollectionView. It can obstruct the views underneath it, capture the touch events, preventing them from reaching the actual scrollView inside the CollectionView, etc. The subviews added using this method will also not scroll as the other elements in the CollectionView do.
The correct way to do what you want is to implement a new type of UICollectionViewCell for the dots, and compute their locations in the prepareForLayout and layoutAttributesForElementsInRect: methods. Basically you'll have either one or two cells in each row. Which ones will have two rows will be determined by you in the methods I've mentioned.
In fact, Apple's docs have a perfect example that's even more complex than what you're trying you achieve. You should check it out from this link.
May I know the purpose of that scroll view ? Because, if you're looking for a subview that displays only a label or image etc., You can use custom collectionview cell instead if I am not wrong... Hope it helps :) :)

Adding a Scrolling Subview to a UITableView (NOT a Cell)

I'm creating my views programmatically. I have a UITableView in my UIViewController subclass that I want to add a scrolling subview to that is not a cell. I want to add some text-based subview to the UITableView that scrolls with the table and starts out above y=0 so the user will only see it if he pushes the table down. That is, it should reside above the first section of my table. If it helps for visualization, I intend to make something similar to those "scroll down to refresh" features and want some indication to the user that scrolling down causes a refresh. Is there any way to do this without something messy like using another UITableViewCell to represent it or abusing the UITableView delegate methods to move a view around whenever the user scrolls?
Simply using [tableView addSubview:] in my viewWillLoad only makes it appear for a split-second then disappear once the table data is loaded. This seems weird to me because UITableView is a subclass of UIScrollView, which is meant to hold other views in it. Using [tableView.backgroundView addSubview] does nothing.
P.S. Why not use a UIRefreshControl for this? I'm still undecided but leaning towards not using one because I don't like how slow that spinning wheel "feels" when the refreshes are usually very very quick. I've been looking at other options like flashing the background subtly and only showing a wheel if it's taking a longer time than usual.
I You can implement pull to refresh with only a table view
To do this using the scroll view delegate, since tableview is a subclass of scroll view.
Set view controller to be the tableview delegate and implement
(void)scrollViewDidScroll:(UIScrollView *)scrollView
When scrollview content offset y value passed a point, add a label to the viewcontroller.view not tableview. When you scroll back or release, remove the view.
You might also be able to add label to the table view and set the frame origin to negative y value, so when you pull the label will move into view (Never tested this do might not work)

iOS UICollectionView not scrolling when cell is touched

I've created a simple grid based UICollectionView but I'm having trouble with the scrolling. If I touch the view itself rather than a cell within it then it seems to scroll correctly but if I touch one of the cells and try to scroll then nothing happens. This is a bit of an issue, as I basically want the grid of cells to completely fill the view, and when the view is filled like that there is nowhere to touch that will actually make it scroll! I guess the easiest way to describe what I'm trying to achieve is a table view but with two columns of cells rather than one.
I can't seem to find anything in the documentation that talks about this issue and I've tried various combinations of "user interaction enabled" settings etc.
One final thing, I do require the cells to respond to a single tap touch (basically to toggle them on and off) so I don't want to completely disable them responding to touches.

Resources