disable touch interaction in UITableView - uitableview

I have a UITableView that draws a subView when the user touches a cell.
The problem is that the subView drawing is animated and if the user is fast enough they can tap a cell multiple times which I want to disable during the animation and afterwards.
I've tried using this:
- (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath {
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
and also a bool variable:
if (isAnimating == NO) {
but neither seem to work. In each case rapid touches screws up everything.
Any help would be great thanks!

Try this...
After clicking on cell set
tableView.userInteractionEnabled = NO;

I know this is an old question however it lacked the swift version so,
in Swift 3 it is:
tableView.isUserInteractionEnabled = false;
and to turn it back on is:
tableView.isUserInteractionEnabled = true;
Just thought this might help someone if they were looking for the answer in swift 3 as I was, and ends up here.

Related

How to set a recent search history drop down for UISearchBar in iOS

I want to set a recent search history dropdown for UISearchbar . I have implemented a dropdown programatically using a UITableView
Logic:
How i have implemented is by setting a UITableView right below the UISearchBar and on click on the UISearchBar it will pop up .
Am initially hiding that tableview in viewdidload and in
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar am unhiding the tableview .
Iam facing too many problems with this :
1. The return button is not enabled when the searchbartext is empty .In that case if i have to cancel/hide the table view again i have to depend on tapgestures .
2. Clicking on the searchbartext again won't trigger any of its delegates. The only time it triggers the delegates on click on the searchbartext is when click on it for the first time then it calls -(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
Do u guys have any other solution / way to implement this feature in a much better way than this ??
Do we have any custom made UISearchBar recent history dropdowns ??
I have searched for a custom UISearchBar recent history dropdown in cocoacontrols,code4app and cocoapods for this no hope dint find any .
Please help me with this .
For your first issue, you can add a category on UISearchBar something like this and this shall always enable your return button on keyboard when tapped on UISearchBar
#implementation UISearchBar (MyAddition)
- (void)alwaysEnableSearch {
// Loop around subviews of UISearchBar
NSMutableSet *viewsToCheck = [NSMutableSet setWithArray:[self subviews]];
while ([viewsToCheck count] > 0) {
UIView *searchBarSubview = [viewsToCheck anyObject];
[viewsToCheck addObjectsFromArray:searchBarSubview.subviews];
[viewsToCheck removeObject:searchBarSubview];
if ([searchBarSubview conformsToProtocol:#protocol(UITextInputTraits)]) {
#try {
// Force return key to be enabled
[(UITextField *)searchBarSubview setEnablesReturnKeyAutomatically:NO];
}
#catch (NSException *iException) {
}
}
}
}
For second issue, why don't you use shouldChangeTextInRange: delegate method which gets called for each entered character.
As a side note, this SO thread has a sample code to do this. This may help you.
Good luck!
I am re-writing the possible steps as per your recent clarification.
keep a flag/boolean to monitor tableview is hidden or not.
in the UISearchBar Delegate method check the serachbar's text field's [obj isFirstResponder] method.
a. if firstResponder =yes --> Show the histroy tableview OR Vice versa.After show/hide is accomplished call below method on UISearchBar' textfield.
*[searchbarobj.textfield resignFirstResponder];*
b. if firstResponder = No---> Don't do anything. leave the method.

Swift 2 button in UITableViewCell

I'm trying to figure out how to know which cell got it's button tapped.
I have a download button in each cell, and I need to know which cell's button got pressed so I can start a download of the correct item.
I have done it before in OBJ-C using blocks, but just can't get it together in Swift 2.
Anyone out there with a bit of code to share?
You can still use your objective-c approach (blocks == swift closures).
There is a lot of ways to do what you need.
You can detect which row was pressed with this:
func buttonTapped(sender:UIButton)
{
let touchPoint = sender.convertPoint(CGPoint.zero, toView:tableView); // get the location of the button inside the tableview
let indexPath = tableView.indexPathForRowAtPoint(touchPoint); // ask tableview which row is at this point
println(indexPath); // it's works! :)
}
Hope it helps.

Force UICollectionView to stop scrolling

A user performs a quick swipe gesture to make a UICollectionView start scrolling (it will gradually come to an halt).
How can I programmatically force the scrolling to come to an immediate stop?
To clarify, I want to allow the deceleration but I need to be able to stop it in code.
Have you tried the following?
[self.collectionView setContentOffset:self.collectionView.contentOffset animated:NO];
the contentOffset property is constantly updated as the collectionView scrolls (even via animation) so at the time of calling the above, it should hopefully force the collectionView to stop its existing animation.
Try this one. Worked for me. :)
self.collectionView.scrollEnabled = NO;
For Swift 3:
collectionView.isScrollEnabled = false
if you have the pagingEnabled and scrollEnabled properties set to true than this should work:
self.collectionView.scrollEnabled = false
self.collectionView.pagingEnabled = false
Adopt the following scrollViewDelegate method to pick up when the user lets go of dragging the collectionView.
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset;
You can then just create your own animation block to set whichever speed/final destination you think looks best using the contentOffset property.

Scrolling in UITableView embedded in UITableviewCell (ios7)

I have UITableView added as subview of UITableviewCell.
In iOS 6 when I scroll internal tableView and reach to the end of it main table view becomes scrolling.
In iOS 7 it doesn't work anymore. If I am scrolling in internal table view it doesn't deliver this scroll event to parent tableView.
Does anyone know how to simply fix it, without manual transferring event from internal tableview to parent?
Additional info:
I find possible reason of problem. But how to fix this problem.
So, I found a solution.
According to tip from #FaisalAli I implement delegate method:
- (BOOL) gestureRecognizer: (UIGestureRecognizer*)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer*)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass: [UIPanGestureRecognizer class]])
{
if ([((UIPanGestureRecognizer*)gestureRecognizer) velocityInView: self].y > 0)
{
// Up
if (self.contentOffset.y <= 0)
{
self.bounces = NO;
return YES;
}
}
else
{
// Down
if (self.contentOffset.y + self.height >= self.contentSize.height)
{
self.bounces = NO;
return YES;
}
}
}
self.bounces = YES;
return NO;
}
And it helped.
I don't think that this is wise solution regarding ease of use for user. You should use Master-Detail Strategy.
Set UINavigationController as rootViewController, then push your Master TableViewController, on selection of each cell you can push new TableViewController having detailed data of selected Cell Item.
Edit
If you really want to add TableView inside a TableViewCell then, please follow link 1 and link 2.

Can I disable / edit the automatic jump-to-top scroll when tapping status bar?

I'm using an app with a tableView that auto-scrolls downward, so tapping the status bar, which would normally jump to the top of the table, causes problems (it begins scrolling but if the auto-scroll ticks, it stops and leaves it somewhere in the middle).
I'd either like to disable it, or at least have shove some code in when it's tapped to temporarily pause the timer and then resume it when it reaches the top.
Are there any means of achieving either of these things?
UIScrollView (and UITableView as a subclass of it) has scrollsToTop property which defaults to YES, making it scroll to top when status bar is tapped. All you have to do is set it to NO.
However, please keep in mind that iOS users might expect this behavior, so turning it off may not be the best idea from user experience standpoint. You can also leave it as YES and return NO from -scrollViewShouldScrollToTop: delegate method if you only need it disabled at specific times.
Actually, handling it via delegate might be a perfect fit for your case:
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
// disable timer
return YES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
// re-enable timer
}
You can try:
[myView setScrollsToTop:NO];
For swift 5
func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
return false
}

Resources