Ankit Sachan
Ankit Sachan

Reputation: 7840

ipad: scroll tableView so that searchbar does not get hide below Keyboard

I have a situation here which I am unable to solve because of lack of expertise in iPhone so kindly guide me thru this,

I have a custom table with two search bar in each cell. When I touch the lowest search bar it hides below key board. So camn you tell me some workaround so that it doesnt hide below keyboard. I tried to use this

[tableView scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated]

but was unable to use it since I was not sure for indexPath.

Please enlighten me on this Thanx in advance :)

Upvotes: 1

Views: 622

Answers (1)

Jonathan.
Jonathan.

Reputation: 55564

You need to know the index path of the cell with the search bar. If the search bar is always in the same cell (it is static) then you just create an NSIndexPath using the below method:

[NSIndexPath indexPathForRow:1 inSection:0];

That is the second row in the first section of the table. 0 means the first, 1 means the second, etc

You just stick that line in the indexPath parameter.

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

This will scroll the 2nd row/cell to the bottom of the tableView, animatedly in other words smoothly and it won't just jump.

Upvotes: 2

Related Questions