I have a TableViewController in my app (well several but this only happens on this particular one).
The content is driven from Core Data using an NSFetchedResultsController and the TVC is a NSFetchedResultsControllerDelegate and uses the methods for updating the table based on content changes (i.e. it runs the beginUpdates, endUpdates etc...).
I've done this a number of times before and so just use the same code. (Also can be found on Ray Wenderlich's site).
Anyway, I have a view (pushed from the TVC) that adds new items in to the CoreData DB. This new item should then be added into the TVC's table.
This is all working fine. I view the Table scroll up and down it fine. Click add. Add the new item. Push back to the TableView and I can see the new item...
BUT
The tableView doesn't allow me to scroll all the way to the bottom now. I can see the new data in the table by scrolling to the bottom and holding the screen but when I let go the tableView bounces back so that I can no longer see it.
I have checked several things...
The frame of the TableView is unchanged before and after.
The contentSize of the tableView DOES change to accommodate the added cells.
When scrolling the minimum contentOffset is 0 both before and after (this is correct).
When scrolling the MAXIMUM contentOffset is the same both before and after (this is not correct).
If I pop back to the rootVC and then push back to the TVC then I can scroll all the way again and see all my new cells.
I did some testing.
If I re-enable autoRotating using - (BOOL)shouldAutorotate then go through the motions of adding the new cells etc then I still can't scroll to the bottom. But if I rotate landscape and then back to portrait then now I can scroll all the way to the bottom.
Off the back of this I tried running the [self viewWillLayoutSubViews]; method after the [self.tableView endUpdates]; but still nothing.
Like I said, I have done this before many times and with no problems. I really don't understand what is happening now.
I finally found a solution that worked!
In the end I had to put [self.tableView reloadData]; into the viewDidAppear method.
That solved the problem.
Related
I have an UILabel that shows me the current date added to the table view header. When the app is running you can see the header right from the start.
What I am after is when the app starts to not see the header, only when you try to drag the table view down, to reveal the label. And when releasing the header should be hidden again.
I think Snapchat uses this technique in their Stories screen.
Any ideas how can this be achieved ?
I'm thinking something with setContentOffset when the app starts to move the table view on top of the header. But then how do I do I know when the table view was dragged and released ?
You are correct that you can use setContentOffset to move the tableViewDown. You can implement UIScrollViewDelegate method scrollViewWillEndDragging(:withVelocity:targetContentOffset:) which will tell you when the user lets go of the tableView and then call setContentOffset(:animated:) to animate the tableView back to its initial position.
I am having an issue with an UITableView.
I am displaying a collection of tracking records. After the user taps on a cell, a detail view controller is displayed with detailed data. My problem is after I call popViewControllerAnimated:YES from the Detail view controller, my table view is reseted and scrolls to the top position automatically.
I am not calling [myTable reloadData]; on viewWillAppear and I find this behavior kinda strange.
Does anyone have an idea what I might be missing here?
Any help or tip would be appreciated!
Thanks,
Granit
It's a known issue.
The more the estimatedRowHeight differs from the actual height, the more the table will jump when the push segue happens. The easiest workaround is to use a much better estimate.
if you don't call reloadData then either you re-add the table somewhere or you popped ViewController was reloaded because of some reason. Does ViewDidLoad called when you pop back?
How about storing the table scrolling state? (contentOffset)
When you subclass UITableViewController, you normally get certain behaviors "for free". For example, when a text field in your table view becomes first responder, the view controller automatically scrolls itself to ensure the field is fully visible.
However, when the table view controller is the detail view controller of a UISplitViewController, this auto-scrolling no longer takes into account the presence of the keyboard. The table view controller will still auto-scroll to keep the text field within the bounds of the screen, but it no longer scrolls to keep the field from being covered by the keyboard.
You can test this yourself by creating a new project using Xcode's "Master-Detail Application" template, and replacing the detail view controller with a table view controller that displays cells with text fields in them.
I would like to understand why the auto-scrolling stops accounting for the keyboard in this case, and if possible how to rectify that without having to duplicate the auto-scrolling functionality myself. BTW, this has nothing to do with overriding viewWillAppear (as in some other questions here about table view controller auto-scrolling).
I know its late but this might help others who are having this issue. This happens to me as well when I added textfield in UITableViewCell. What I did was to remove
superViewWilAppear:animated
line in viewWillAppear method.So the method looks like this
-(void)viewWillAppear:(BOOL)animated{
//[superViewWilAppear:animated];
Your rest of code
}
But what this does is it removes the auto scrolling all together and you have to manage the scrolling of UITableView when textField starts editing. Don't know if this solved your problem but it will save you the trouble of considering keyboard height for different devices and its better to manage on your own. Also I am not sure if this is the right way to do it but it worked for me.
I have implemented a pull to refresh control using UIRefreshControl with a UICollectionView. It works well, however, when I pull the collection view beyond the point where it initiates new data fetch, collection view jumps down by what seems to be navigation bar (plus status bar) height, i.e. the motion is not smooth.
I first thought this might be because of iOS7 content offsets, but this happens in iOS6 as well.
Any ideas what can be wrong or what I should check?
From UIRefreshControl reference:
Because the refresh control is specifically designed for use in a
table view that's managed by a table view controller, using it in a
different context can result in undefined behavior.
Basically, saying that it will play nicely only when used inside UITableViewController. When used elsewhere, this weird bounce occurs.
In my view I am using a UITableView that is controlled by a UITableViewController on the top half of the screen. The remaining screen is used for a UIScrollView that contains a view that is controlled by the main UIViewController.
When I perform a pull down to refresh in the UITableViewController, (for some reason if the number of table entries is less than or greater than the initial load value, the UIScrollView in the main UIViewController's frame gets changed to the screensize...
Essentially it breaks my paging unless I reset the scrollview back to the intialized size...
I have no idea why this happens as the UIScrollView is not used in the UITableViewController. The only scrollview that is used in the UITableViewController is the UITableView's to handle pull down to refresh...
Does anyone know why the main UIScrollView's contentSize gets changed randomly when it shouldn't even been accessible from the UITableViewController class?
Thanks
Just tried it here, and I can't duplicate your experience. I'm guessing you have an unexpected or inconsistent view/controller hierarchy? Look at the controller of the table and scroll views' common superview. Anything fishy there? Remember: view controllers manage sets of views. Container view controllers manage other view controllers and have special rules (see: The View Controller Programming Guide, esp. -addChildViewController:, etc.).
I'd suggest opening a blank project and trying to recreate the problem in its simplest possible form. If it's magically fixed, what's different? If it's still giving you trouble, send us a link so we can see the details of how you have things wired.