How to hide tableView header? - ios

I have my tableview with search bar added in it.
actionsTableView.tableHeaderView = searchController.searchBar
I want my tableView appear with hidden header, which will appear when I scroll up.
As a reference you can have a look on Telegram/WeChat/WhatsApp messengers, they have implemented this feature.

Try this inside of viewDidLoad,
[self.myTableView setContentOffset:CGPointMake(0.0f, 40) animated:NO];
Note: Add your UISearchBar inside of UITableView

Add your searchBar and tableView in a view(say mainView).
Add mainView to the view controller and assign its top(topConstant) to -40(considering its the height of search bar) , and assign the leading,trailing and bottom to view controller.
Now assign scrollview delegate to your class and check if tableview is scrolled on top by checking its velocity.
now add Animation and set topConstant to 0.

Related

UISearchController as UITableViewHeader

I am having a view controller with a UITableView and a Custom View.The storyboard configuration is Custom View is alligned with top, leading and trailing margin of my view controller's main view.Custom View is having a constant height. UITableView's top is alligned with bottom of the Custom View. UITableView's leading, trailing and bottom is alligned with leading, trailing and bottom of main view. I am adding a UISearchController's search bar as UITableView header. This view controller is pushed on UINavigationController Stack. Now when user clicks on search bar navigation bar hides to make way for searchbar.But as custom view is above the UITableView it accomodates the position where UISearchBar should have been. I want to move Custom View out also and take the UISearchBar position which would have been in normal scenario without Custom View above. Help will be appreciated.
Set the the IBOutlet for the Custom View's Height constraint and when user clicks on search bar then set e.g "customview.heightConstraint.constant = 0"
in search bar delegate method
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar){
customview.heightConstraint.constant = 0
}

How to add button end of uitableview with swift

I want to add button or row end of uitableview. I used tableview footer but its not solution for me. I also tried others way but ı didnt found any result. How can ı pass this problem.
Thanks..
Use UIViewController instead of UITableViewController:
In storyboard add UITableView to your view controller
Create an IBOutlet for UITableView - connect it
Conform your view controller to UITableViewDelegate and UITableViewDataSource
set tableView.delegate = self and tableView.dataSource = self
In storyboard add a button bellow table view and set top button's constraint to be few (e.g. 4) points away from table view's bottom constraint
Create IBOutlet for button and connect it
Add height constraint for your button - set it to 0.0
Set button's title to empty string ("")
Create IBOutlet for button's height constraint and connect it
Check when your table view reaches the end - to check whether your table reached the bottom you can implement tableView:willDisplayCell:forRowAtIndexPath: and check if indexPath.row is the last item in your data source (there are other ways too so you are free to check them)
When your table reached the end - simply set button's title to your desired title with button.setTitle(for) and animate button's constraint to another height (big enough to see the whole button)
When button is pressed you can just do the opposite animation: set button's title to "" and animate height constraint change back to 0.0

UItableview rows overlaps textfield

I have view controller which has a tableview and below the table view there is a textfield(which is not part of tableview cell) and a button(just like whatsapp chat window)
What I see is, when I start adding objects to the table, it grows up to the text field and grows beyond and below the text field at the bottom.
There are a few different ways to go about it,
In the IB, Make sure that your tableview comes before your textfield and button, The top most view is the farthest one.
You can use UIView methods such as
sendSubviewToBack: (Send tableview to back)
bringSubviewToFront: (Bring textfield and button to front)
Have you tried setting frames to each of these elements?
CGFloat tableViewHeight = 400;
self.tableView setFrame:CGRectMake(0, 0, CGRectGetWidth(self.view), tableViewHeight);
I'd place the textField and button as subviews to a view - self.textFieldElementsView and set the view's frame under the tableView:
self.textFieldElementsView.frame = CGRectMake(0, CGRectGetMinX(self.tableView.frame) + tableViewHeight, CGRectGetWidth(self.view), CGRectGetHeight(self.view)-tableViewHeight);

How to clip table view cell to view above

I have custom tableViewCell and View above it in tableView. After taping on button views height increase and cover cell's view. How to clip cell to bottom of view for changing position of cell and don't allow view to cover cell?
I tried to override setFrame: method in my cell. But it doesn't work.
If the view above the cells is a table header view, you should reset that view as the header after you increase its size. So, if you're view was called myHeader, you would do this after changing the size ,
self.tableView.tableHeaderView = myHeader;

How to add a search bar at the bottom of a table view in Xcode?

I am developing an iOS application, and I want to add a search button that initiates a search of a table view. When searching, the search bar should not be scrolled with the table cells.
To make a search bar (or any view really) "stick" to the top or bottom of a UITableView there are two approaches:
Adjust the frame of the table to be the view height minus the height of your bar, and then set the bar's frame to {0, 0, CGRectGetWidth(self.tableView.frame), CGRectGetHeight(self.tableView.frame)}, which would position it statically at the bottom of the view. If you are using a stock UITableViewController, you'll need to do some additional work because self.view and self.tableView both point to the same object. You'll need to set a new UIView to self.view which will then be the container for the table view and your search bar view.
Add the bar as a subview of table, then implement UIScrollViewDelegate in your controller and use scrollViewDidScroll: (which fires whenever the user scrolls the view) to update the bar's position. The new position would be something like:
CGRect adjustedFrame = self.searchBarView.frame;
adjustedFrame.origin.y = self.tableView.contentOffset.y + CGRectGetHeight(self.tableView.frame) - CGRectGetHeight(self.searchBarView.frame);
self.searchBarView.frame = adjustedFrame;

Resources