Reputation: 969
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.
Upvotes: 0
Views: 783
Reputation: 57050
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.
Upvotes: 2
Reputation: 2251
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.
Upvotes: -1