adding subviews to UITableViewCell issue - iphone

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];

Related

UITableView won't reload contentSize

I have a UITableView, that add's some data after the UITableView reloaded for the first time, but I can't scroll down to the new data if I scroll I see the new data but then it scrolls back automatically, and yes I reloaded my UITableView, so I checked my UITableView contentSize and it won't change after the reload but after I go to another view (UINavigationController) and pop back the UITableView contentSize does change and it works! How can I fix this?
Thanks!
I had a similar issue and solved it using the same technique as Daan (as far as I can tell).
In my case I was using a static UITableView that had some of its rows and sections hidden initially (by setting appropriate return values from numberOfSectionsInTableView: and tableView:numberOfRowsInSection:). I was pushing a VC onto the nav stack to collect additional data which I would then use to fill in the hidden tableview sections, calling reloadData on the tableview to refresh it.
This worked fine in iOS7, but in iOS6 the tableview's contentSize.height never changed from its initial value (218 pts) to the taller value (504 pts) derived from the addition of the new sections. As such, you could not scroll to the content at the bottom of the tableview. Trying to force the contentSize did not work as it was immediately set back to 218.
Changing the tableView's contentOffset allowed me to scroll to the bottom of the content, but if you tapped the UITextField in the last cell, it would whip off screen as the keyboard was shown.
I finally was able to come up with a solution that worked in both iOS6 and iOS7 without issue. I used the old beginUpdates / insert or delete rows and sections / endUpdates methods of UITableView, as follows:
// change the tableView's data source to reflect insertions/deletions
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:#[ [NSIndexPath indexPathForRow:1 inSection:0] ] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView insertSections:[NSIndexSet indexSetWithIndexesInRange:NSRangeFromString(#"1,3")] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
As you can see, in this particular case I had to remove a row from the first (and only) section and add three sections to the end of the tableview.

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];
}

UITableView reloadSections creates a sectionheader on top of a row

I have a tableview with one sectionheader. With the following codesnippet I reload the tableview when a user swipes the view left or right.
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
When a user has scolled downwards in the tableview and then swipes, this codesnippet reloads the rows correctly but the sectionheader is created on top of the row where the swipe was initiated.
Can anyone tell me what I'm doing wrong & how to solve ?
thanks
Frank
I think the problem is that reloadSections:withRowAnimation seems to be buggy on iOS 4.0, and it was fixed in one of the later versions.
On iOS 4.0 calling reloadSections:withRowAnimation results in table header appearing in the middle of a row, and on 4.3 it works fine. I've replaced it with reloadData which is less optimal, but works on 4.0 too.

slightly different scrolling needed after searching

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];
}