How to make UITableView header to show only when dragging down table view - ios

I have an UILabel that shows me the current date added to the table view header. When the app is running you can see the header right from the start.
What I am after is when the app starts to not see the header, only when you try to drag the table view down, to reveal the label. And when releasing the header should be hidden again.
I think Snapchat uses this technique in their Stories screen.
Any ideas how can this be achieved ?
I'm thinking something with setContentOffset when the app starts to move the table view on top of the header. But then how do I do I know when the table view was dragged and released ?

You are correct that you can use setContentOffset to move the tableViewDown. You can implement UIScrollViewDelegate method scrollViewWillEndDragging(:withVelocity:targetContentOffset:) which will tell you when the user lets go of the tableView and then call setContentOffset(:animated:) to animate the tableView back to its initial position.

Related

Table View is taking interaction when a view of same bounds is added above that in OS X

My app contains a Table View which is scrolling and taking events properly. But after that I have to show a custom pop up to screen for that I have added a full view over the Table View. But after adding the view over Table View, Table view is still scrolling and taking events.
Please help if anyone have knowledge about that...
Thanks
The best way to achieve this is to add a blur view into your nib file first. This is better approach as the user is made aware of the current enabled object.
Once you add the blur view over the tableView you are showing, add your custom pop-over. This would maintain a clear demarcation between the two views and you would be able to achieve the functionality you want as the touches won't flow to your tableView.
Follow below steps may work:
Add overlay view on screen to show data on top of table view
make TableView Disbaled as soon as u add view on it.

Drag & Drop in MAster-DetailView Controller in iOS

I want to drag from the masterview tableview Cell to DetailView.
I try with touchesBegan & touchesEnded method but not working.
Can you please help me for this?
Thank you
This is actually not easy. You can start by
Adding a pan gesture recognizer (UIPanGestureRecognizer) to the root view controller's view (UIWindow.keyWindow!.rootViewController!.view).
When the pan starts (i.e. user touches the screen), loop through the master view's table view's visible cells to see if the point is inside any cell by using UIView's convertPoint:fromView:. You may need to adjust timing to avoid interfering with table view's scrolling and tapping.
If a cell contains the pan's point, create an "indicator view" (that shows that user is dragging) and add it to the root view controller's view, on top of everything else and position it properly, e.g. under user's finger.
When the pan changes (i.e. user moves his finger), update the indicator view's location.
When the pan ends (i.e. user releases his finger), check if the point is inside the detail view and do whatever you need to do.
Check this out. It demonstrates how to do drag drop within a view. Your problem is more complicated as it involves different view controllers, hence the touch handling must be done at a level higher than both master and detail view controllers.
Why are you using touchesBegan & touchesEnded methods? If you have the tableView you should use didSelectRowAtIndexPath delegate method. And you can also use segues if you are using storyboards.

Can't touch UITextField after scrolling

I have a ViewController setup like so:
-View
--scrollView
---contentView (UIView)
All of my content is in the contentView. Most of the content is UITextFields that I added programmatically to fashion a form-like setup. I can touch the text fields when I first enter the View Controller to bring up the keyboard to type on them, however, as soon as I scroll down (so I can see the rest of the textfields on the view) none of them respond to touch, even the ones that I could originally see and interact with when I first entered the view controller. There is, however, one button that I added from the storyboard that will continuously accept touch events even after scrolling, but the textfields I added programmatically will not.
I am not sure what code to place here and I don't have the first clue as to where to look for this sort of situation. Any help would be awesome, this is my first app so things are coming along slowly. Thanks so much in advance.
Code Here

didSelectRowAtIndexPath in UITableViewController not working

I have a HomeViewController which is loaded with views. On the top is the map view, so now when I create the table view on the top of it which does not cover the whole screen but little portion of it(actually its a drop down list in the form of tableview), it displays fine with cellForRowAtIndexPath working fine but didSelectRowAtIndexPath is not working at all.. I have tried using break point on it but its not calling this method actually infect it is selecting the view at the back i.e. the map view. Clicking on the table view is actually changing the map view behind..
I am having the table view coming from another class which is inherited by the HomeViewController
I am using some NIDropDown class .. Its working fine if no view is behind it (only superview) but not woking if it has any view behind
Few things to be ensured-
1) As you said your table view is on top of the map view. If this is the case than it's alright.
2) Check if the user interaction is enabled for the table view or not.
3) Check if you have set the delegate of the table view(responsible for detecting events on table view).
4) Check if you have not set the delegate to nil somewhere and still the table view is visible.
I think if you follow the above steps than table view's events should be triggered, otherwise it will be good if you post your code to get some other clue regarding the issue.
That cellForRowAtIndexPath works is an indication that the datasource property (UITableViewDataSource) is properly set.
If didSelectRowAtIndexPath is not firing, you should check if the delegate property (UITableViewDelegate) is properly set, either in Interface Builder or in code.
After read your problem, i strongly believe there will be two issue :
1) Map view issue, if you shows table view as *callout view
Reason:
You supposed to use “MKAnnotationView” callout view for show drop down over map.
if you do so then make sure MKAnnotationView view height would be exact same of your drop down view’s(NIDropdown view’s) height.
Table view not able to get touch, that's why it would not send message of didSelectRowAtIndexPath to it's deletegte.
In your case might be Map view getting touch, which did not suppose to get until table view is at screen.
2) Table view rest out of bound on super view
Reason:
in such case table view display normally but actually its bound goes out of own super view bound.

UITableViewController auto-scrolling stops taking into account keyboard when shown from a UISplitViewController

When you subclass UITableViewController, you normally get certain behaviors "for free". For example, when a text field in your table view becomes first responder, the view controller automatically scrolls itself to ensure the field is fully visible.
However, when the table view controller is the detail view controller of a UISplitViewController, this auto-scrolling no longer takes into account the presence of the keyboard. The table view controller will still auto-scroll to keep the text field within the bounds of the screen, but it no longer scrolls to keep the field from being covered by the keyboard.
You can test this yourself by creating a new project using Xcode's "Master-Detail Application" template, and replacing the detail view controller with a table view controller that displays cells with text fields in them.
I would like to understand why the auto-scrolling stops accounting for the keyboard in this case, and if possible how to rectify that without having to duplicate the auto-scrolling functionality myself. BTW, this has nothing to do with overriding viewWillAppear (as in some other questions here about table view controller auto-scrolling).
I know its late but this might help others who are having this issue. This happens to me as well when I added textfield in UITableViewCell. What I did was to remove
superViewWilAppear:animated
line in viewWillAppear method.So the method looks like this
-(void)viewWillAppear:(BOOL)animated{
//[superViewWilAppear:animated];
Your rest of code
}
But what this does is it removes the auto scrolling all together and you have to manage the scrolling of UITableView when textField starts editing. Don't know if this solved your problem but it will save you the trouble of considering keyboard height for different devices and its better to manage on your own. Also I am not sure if this is the right way to do it but it worked for me.

Resources