Animating Reloading of UITableView - iphone

I am trying to animate table rows in a UITableView in an iPhone project as I swipe across the screen to reload the data.
When I disable animations and only call reloadData, table continues responding to swipe gestures.
When I add animations with the reloadSections:WithRowAnimation: method, table stops responding to swipes, and only the navigation bar at the top responds to swipes.
Another change is that, table starts responding to selection and I have to manually disable it again. I suspect these two issues might be related.
I am using the swipe detection code over here btw: 1

My code for managing the gesture was in a UIView which contained another UIView which in turn contains the UITableView. It turns out that the user interaction of the UIView which is the superview of the UITableView was Enabled. Setting it to disabled caused the gesture to move up in the responder chain, and solve the problem.

Related

Swipe gesture recognizer not working in vertical directions

guys, I'm totally new to Objective C and XCode, so don't be too harsh on me for such a question. In fact, this is my first question on StackOverflow ever. The problem is the following:
I need functionality for closing the keyboard when tapping or scrolling anywhere outside the textField that is currently first responder.
I managed to implement it for tap and horizontal swipes with the following code (right swipe example):
UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(closeKeyboard:)];
swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.tableView addGestureRecognizer:swipeGestureRecognizer];
swipeGestureRecognizer.cancelsTouchesInView = NO;
And in fact, later I figured out how to do it using solely interface builder. But vertical swipes just would not work, neither when I do them programmatically, nor through the IB. I suspect that the problem is that my tableView scrolls vertically on the screen, thereby preventing the call of the swipe, but I still have no idea on how to overcome this issue.
I would greatly appreciate your help! Thanks.
I saw, that you are trying to add this vertical gesture to a tableView. So you don't need to add a vertical swipe gesture . You have to implement UIScrollViewDelegate protocol, and implement the -scrollViewDidScroll: or -scrollViewWillBeginDragging: methods. In these methods you can catch if your tableview scrolling, and if your tableView is scrolling, call your closeKeyboard method
the UITableView basically uses UIScrollView & when you implement the UITableView delegate, you also implement the UIScrollView delegate (because behind the scenes, the UITableViewDelegate has implemented the UIScrollViewDelegate)
You do not have to manually implement the UIScrollViewDelegate & you can simply start using any UIScrollView delegates you want such as the -(void)scrollViewDidScroll:
But if you want vertical swipes to work on the tableview then it can be done in the following dirty & totally buggy technique. (Basically this is how NOT to do it)
MAIN property is setDelaysContentTouches on your tableView object to NO.
setDirection on your UISwipeGestureRecognizer object to detect vertical up & vertical down swipes.
Set the swipe gesture onto the tableView object.
example:
[self.tableView setDelaysContentTouches:NO];
UISwipeGestureRecognizer *mySwipe = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:#selector(closeKeyboard:)];
[mySwipe setDirection: UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown];
[self.tableView addGestureRecognizer:mySwipe];
Finally, you'll get it to work but it works real bad.
Most of the times, the swipe is ignored since you need to swipe
really really fast and cover a decent distance within the swipe action.
When the swipe works, the table does not scroll.
So, as you see, it's really sad and dirty thing to do.
The reason is that the scrollView handles the content touches in a very specific way.
To decide if the touch is to be handled or to be forwarded, the
UIScrollView starts a timer when you first touch it:
If you haven't moved your finger significantly within 150ms, it passes the event on to the inner view.
If you have moved your finger significantly within 150ms, it starts scrolling (and never passes the event to the inner view). Note:
how when you touch a table (which is a subclass of scroll view) and
start scrolling immediately, the row that you touched is never
highlighted.
If you have not moved your finger significantly within 150ms and UIScrollView started passing the events to the inner view, but then
you have moved the finger far enough for the scrolling to begin,
UIScrollView calls touchesCancelled on the inner view and starts
scrolling. Note: how when you touch a table, hold your finger a
bit and then start scrolling, the row that you touched is highlighted
first, but de-highlighted afterwards.
These sequence of events can be altered by configuration of
UIScrollView:
If delaysContentTouches is NO, then no timer is used — the events immediately go to the inner control (but then are canceled if you move
your finger far enough)
If cancelsTouches is NO, then once the events are sent to a control, scrolling will never happen.
Note that it is UIScrollView that receives all touchesBegin,
touchesMoved, touchesEnded and touchesCanceled events from CocoaTouch
(because its hitTest tells it to do so). It then forwards them to the
inner view if it wants to, as long as it wants to.
source: https://stackoverflow.com/a/844627/2857130

Stop UITableView from animating for keyboard

I have an UITableView with a single cell that contains an UITextView. When calling -becomeFirstResponder on the UITextView my UITableView gets messed up by the automatic animation. This only occurs when the UITextView has to scroll down for the end of the text.
I already tried disabling scrolling on the UITableView.
Depending on the needs of your interface, you could probably do what you're asking by making the parent view controller an instance of UIViewController instead of UITableViewController (which is what provides that "slide to get out of the way of the keyboard" behavior).
Indeed, if your UI consists solely of a text view, you probably don't need a table view at all.

Canceling the scrolling animation when keyboard pops up on iphone

I have a UIViewController that contains UITextField. I set the inputAccessory of the textfield to a UIToolbar that I create.
My ViewController's view is inside a UIScrollView (To handle the events of keyboard popping up)
Before:
Now, when the keyboard pops up, suddenly my ScrollView is setting it's contentOffset.y to 64 with animation, so part of my view is pushed above the top of the screen:
After:
This is done by the framework because I'm using a toolbar for inputAccessoryView.
If i'm dropping the toolbar there is no animation and no content offset.
Is anyone knows how can I disable this automatic animation and scrolling?
Thank you!
You can use a combination of boolean flags and your UIScrollViewDelegate to prevent the scrolling from taking place. Scroll view delegates can be used to detect when scrolling is taking place, modify the type of scrolling, and also simply prevent it from happening, so your best approach is probably to look into detecting when the keyboard goes up (via a notification or text field delegate, whichever is more appropriate) and using that in combination with your scroll view delegate.

pass vertical scroll event from uibutton to tableviewcell

I placed a uibutton inside of a tablecell. When i try to scroll up and down through the table, the table does not scroll if i place my finger on the button and scroll from there. How do I pass the scroll event up the responder chain so that the tableview can handle the scrolling?
This is very deliberate behavior in the frameworks. UIScrollView explicitly avoids taking over touch events that begin on a button. Is there any particular reason you want this to happen?

I have a UI Scroll View with UIButtons on top. How do i make it scroll when they touch and drag the buttons?

I want something similar to how the iPhone homescreen works. I have my scrollview inside my main view, which scrolls to the right, but when you touch on the UIButtons, they become highlighted and dragging means they don't end up getting pressed but also the scrollview doesn't end up scrolling. It doesn't do this on the homescreen. How can i make it similar to this?
A touch-down-drag is a completely different event. Apple doesn't support this directly—you'd have to code it in—start tracking the touches using the gesture responders as soon as a touch-down-inside is detected, then scroll the same amount, and stop scrolling at a touch-up-outside (or inside). This would most likely fall under the category of unusual use of interface elements, and could very well get you rejected.
I think this is a better answer to the question:
UIScrollview with UIButtons - how to recreate springboard?