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];
}
Related
So I read here that I can simply drag a UITableViewCell to the bottom of my UITableViewController in storyboard and have it act like a footer. This footer row has an activity indicator in it that's it. It's width is 320 and height 55 with the indicator centered in the row. Note that it's a UIView rather than a UITableViewCell because I can only get it to work with the former.
First, The UITableView doesn't stop at the footer. One can see the footer if he extends his scrolling beyond the bottom of the UITableView. As soon as the user releases his finger, the footer disappears from site as the UITableView returns its scrolling back to the last element. I am trying to do what Instagram is doing - if you scroll to the bottom you can see their custom activity indicator at the bottom and the UITable will remain its scrolling position at that indicator. How can I achieve this?
Second, I have some custom scrolling performed by certain user actions. Right now, I have the following code:
if (row + 1 < [self.tableView numberOfRowsInSection:0]) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:row+1 inSection:0]
atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
} else {
// TODO scroll a little down so the user can see the activityIndicator
}
How can I tell my tableView to scroll programmatically to the footer and have it stop there?
Third During the very beginning, my UITableView has to fetch things from my server before it can populate the tableView. Unfortunately i can't get the footer view to maximize the space of the UITableView so that the activityIndicator will appear in the center. Right now this is how it looks:
I think I have the structs set correctly:
I suspect that having a UIView within a UITableView might prevent the view from maximizing.
Summary
Any recommendations on the above issues? I apologize for the length of this question, but I feel that they are all related to the same problem mentioned above.
I finally figured it out.
With regards to #zing and #Lithu answers, that worked. However, returning a footerView from this method forces the footerView to "stick" to the bottom of the TableView. By this I mean that the footerview will always be shown (which is not something I want)
I finally used self.tableView.footerView = MyView. I disabled ALL the spring and struct settings on my UIView and it fits perfectly. (I've previously set it to maximize hoping to have it maximize when there is nothing in the table)
Regarding centering the activity indicator: I ended up setting the footer view to hidden if there's nothing in the UITableView (by checking in numberOfRows). I programmatically added the ActivityIndicator in the center if this occurs.
Thanks for all the answers!!
Did you try to do it in the proper delegate for UITableview Footer
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Use This code to add any view in the footer.
e.g.
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.tblView.frame.size.width, 49)];
return footerView;
}
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.
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
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];
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];
}