UISearchbar inside UITableView as the last cell hiding the keyboard - ios

I have a UITableView in which I have several custom cells and my last cell contains a UISearchbar in it. I have wired up the appropriate delegates and referencing outlets and can get the keyboard to show up.
The problem I am facing is that the searchbar is at the very bottom of my tableview i.e. it is part of the very last cell. So even though the keyboard gets shown, the searchbar is hidden below it as I suspect it is unable to scroll to that location since its the last cell in the view.
Does anyone have any thoughts on this and how to overcome this situation.

The easiest solution is to have your view controller be a subclass of UITableViewController. This type of view controller will handle issues exactly like these.
If you cannot, you should listen to keyboard will show/hide notifications and set contentInset and scrollviewIndicatorInsets bottom of the table view to the keyboard height. Then you can scroll the specific cell into visible. When the keyboard hides, set the bottom to the previous value.

Yes....Two ways
1) either you can change the frame of whole tableView and pull the whole table up by decreasing the y position of tableView
[tableView setFrame:CGRectMake(100,100,100,100)];
or
2) You can change the contentOffset of the table to programatically scroll the tableView's last cell so that it is visible to the user.
[tableView setContentOffset:CGPointMake(0,400) animated:YES]
Hope this will help you.

Related

Setting contentInset of collectionView which contains a tableView

My situation is that I have a collectionView which has two types of cells. The first cell type is a simple editable UITextField, then second contains a UITableView with editable UITextFields inside its cells.
My problem is that when the keyboard shows up due to the text fields inside the a table view cell and I change contentInset the change does not take place.
This is the code I am using to change the insets when the keyboard appears and its the same code for when the textfield in the collection view cell is selected, which works.
self.view.setNeedsLayout()
self.collectionView.contentInset.bottom = inset
self.view.layoutIfNeeded()
There must be something that I can't think of that is preventing contentInsets to change.
I also have a custom UICollectionViewLayout although I don't think this matters as that is only concerned with the contents of the collectionView, not the insets.
Any help would be much appreciated.
Turns out the reason it was working was because the cell with the textview in it was doing some magic autoscroll, while the cell with the table view textview was not, I'm guessing as it was to far nested in the view stack to handle this.
My fix was to adjust the contentOffset so as to force a scroll.

UIPickerView in UITableViewCell showing behind next Cell

I have a tableview with a number of custom cells. The problem I am having is that the cell with the pickerview is 'bleeding' behind the neighboring cell.
Once I push another view controller and pop back, the neighboring cell is properly opaque until I manipulate the picker, at which point the issue materializes again.
The cell is, in fact, opaque. I have set it as such in both the storyboard and code. I have also tried setNeedsLayout and layoutIfNeeded in cellForRowAtIndexPath.
Set clipsToBounds property to true to each cell in the method cellForRowAtIndexPath.
You can set this property in the Storyboard if you are using prototypes cells.
You need to provide more information.
But if I understand correctly, you should hide the cell that contains the picker and only show it when the user will input.
Here is a tutorial on how to hide the cell, like the calendar iOS app does.
http://www.appcoda.com/expandable-table-view/

An extra view appears in cell when pressing reorder dragger, why?

I have an UITableView with varying height, and when pressing reorder control, in the cell view structure a new view appears. Normally it is not a problem, but sometimes its height is quite big, and it overlaps, with cell below.
Why this view appears?
How can I get rid of it?
Or prevent to overlap other cells?
This view is part of the reorder mechanism and can't be removed. It is used to hide the cell content while you drag a screenshot view above the tableview.
If you set the cell clipsToBounds as YES, it should prevent it's content overlapping other cells.

TextField superposed in tableview

I initially load a hidden tableView with some data and show this when I press a button, simulating a drop down menu.
In the same view, I have a UIButton which when pressed, programmatically creates another UIButton and a UITextField.
The problem is that when I load again, the tableView and all the textFields and buttons are superposed.
This is what happens:
My question is what can I do for keep the tableView in front of in the view.
When you do -addSubview:, the view is added as the top-most view.
Which is the reason why your newly added textFields are appearing above your tableView.
The quickest way to solve your issue would be to make the tableView the top-most view when you're planning to show it.
Example:
[yourTableView setHidden:NO];
[self.view bringSubviewToFront:yourTableView];
Assuming that self.view contains yourTableView
What you are experiencing is a cell reusability issue.
If you are adding controls on cells, when they get reused They will keep the textFields which gives you this strange juxtaposition result.
You have to take proper care of removing the textField which makes things more complex.
Solution is to subclass UITableViewCell so that you have prototype cell with textfield and another one without.

UITableView stops scrolling enough after I add/remove a view to the superview of table view

Here is the problem that I'm facing. I have UITableView inside main view. When user taps menu button, view is added to the view hierarchy of superview, and this view covers all screen, except the menu button. That is I call
[self.view insertSubview:self._menuView belowSubview:self._menuButton]
After user clicks the menu button again I call
[self._menuView removeFromSuperview]
However, after this, the UITableView stops scrolling, actually it scrolls, but just a little, couple of pixels, and then bounces back to the location on which it was before I inserted _menuView. I've monitored the menu hierarchy after inserting and removing the _menuView, it is actually removed, and also there is no view which covers the UITableVIew, so there is no chance that some other view steals touches from UITableView. What can be the problem? Any ideas?
EDIT 1: I've noticed besides not being able to scroll, another strange thing happens. When I show menuView, the tableView is scrolled to top, without animation. (the menuView is half opaque only, so I can see the tableView underneath it)
EDIT 2: I've monitored contentSize and contentOffset of tableView before and after inserting _menuView, the reason for not being able to scroll is that somehow contentSize is being changed.
TABLE VIEW BEFORE INSERTING MENU - contentSize:{Width=320, Height=10519} contentOffset:{X=0, Y=3980}
TABLE VIEW AFTER INSERTING MENU - contentSize:{Width=320, Height=44} contentOffset:{X=0, Y=0}
As You can see, the height is changed to 44 that's why I'm not able to scroll. And Also, as I've said in EDIT 1: tableView is scrolled to top - so as you can see contentOffset is also zeroed. Any ideas why content size changes automatically?
Thanks in advance.
i think there is problem with your tableview frame. right after removing subview, try to set frame of your tableview at its original frame.may this will solve your problem
Content in the UITableView organized automaically and designed only to show cells & header/footer elements. To proper working you should wrap your table into parentView and add your menu to that parentView rather than to the UITableView. You can also try to call reloadData method on table since it can restore the content size of the view.

Resources