slightly different scrolling needed after searching - iphone

I have a UISearchBar below a header-view. This header is 64px hight. If the searchbar gets touched, the parent view will move 64px up — fine.
After finishing searching the parent view will only move down, as long there is still free space below it. And the top is out of the visible bounds.
But I want to move it back to the original position every time searching finished. How can I achieve it?

Implement the UISerachDisplayDelegate-method -searchDisplayControllerDidEndSearch:
like this:
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}

Related

UITableView scrolling to last cell only displays half of the cell

I want to scroll to the bottom of my tableview that contains custom cells.
Here is the code I am using to scroll:
NSIndexPath *lastMessage = [NSIndexPath indexPathForRow:[self.conversation.messages count]-1 inSection:0];
[self.messageTable scrollToRowAtIndexPath:lastMessage atScrollPosition:UITableViewScrollPositionTop animated:YES];
This scrolls the view; however only the very top of the last cell is visible with ~3/4 of the cell still below the fold that I have to manually scroll down to. Any ideas on how to fix this?
Turned out to be a timing issue. The tableview hadn't fully rendered yet when I called that method from viewdidload (contentsize of 0). Calling this method in viewDidAppear works brilliantly though.
It seems like the UITableView is confused about how big your cells are. Set the rowHeight property on the UITableView to the height of your custom cell.

error when usning UITableViewScrollPositionMiddle:atScrollPosition: causes my tableview to become unscrollable

I am currently trying to get my uitableview to automatically scroll to a selected cell.. I am about halfway there however when I now use this method (below) inside tableView:cellForRowAtIndexPath: and its definatly centering the uitableview to the previously selected indexpath however it then dosnt allow the user to scroll the rest of the table.. it stays fixed on that position..
//Center previously ticked cell to center of the screen
[self.tableView scrollToRowAtIndexPath:oldCheckedData atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
Here is an example of what I am trying to achieve.
Okay, the one method I missed trying was the one that solved the problem... here is the answer.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//Center previously ticked cell to center of the screen
[self.tableView scrollToRowAtIndexPath:yourSelectedIndexMethod atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}

UIPickerView and UITableView subview: problem with scroll after new data given

I need assistance. I made a UIPickerView that has a UITableview subview. I iterate over the pickerArray to generate data for the table. As one chooses the component the tableArray changes. Everything works fine except the scroll. If you scroll down and then select another component the tableArray changes but the position you chose remains static. So, if you scroll to the middle of the table and then select another component you will be looking at the new table data from the middle as well. I want the table to scroll back to the top of the table and not stay at the middle.
On your table view, call:
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];

How to make tableView Scroll Automatically to top/bottom?

This is just a test, which i might add it to the app. Well.... I have a tableView.
If click button1, I want the tableView to scroll up automatically to the top.
If I click button2 I want the tableView to scroll down automatically to the bottom.
How can this be done ? What about Scroll Speed ?
You can also look at the scroll view's setContentOffset:animated: method.
Going to the top would mean,
[self.tableView setContentOffset:CGPointZero animated:YES];
and the bottom would be,
CGFloat height = self.tableView.contentSize.height - self.tableView.bounds.size.height;
[self.tableView setContentOffset:CGPointMake(0, height) animated:YES];
You won't have control over the animation duration.
The only problem with scrollToRowAtIndexPath:atScrollPosition:animated: is that it might not be helpful when section and table headers are set.
scrollToRowAtIndexPath:atScrollPosition:animated:
Scrolls the receiver until a row identified by index path is at a particular location on the screen.
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

adding subviews to UITableViewCell issue

I have a UITableView , in which if I tap on one of the rows it adds a subview at the bottom. The issue is that when I tap the last row in the table, it hides the subviews and having me to scroll to the bottom to see it. It's a small bug, but what is the best way to remedy this issue.
One way I can think of is to scroll down to the bottom of the row if the last row is selected.
This doesn't seem to be a very good solution though.
Here's a video illustrating my issue
You may want to try something like this in the didSelectRow method:
if (indexPath.row == [dataArray count]) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row
inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
I've also used the following for making the last row visible (though from your video I do not think this will work for your situation)
[guessesTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];