iPhone Dev - Scrolling to a new position in a tableview that is currently off-screen - iphone

Say for example I have a tab bar controller where one of its views is a tableviewcontroller, and another one is some other view. The other view has a button in it that when pressed, should make it so the tableview (which is not on the screen while you're pressing the button) repositions itself so that some specified cell is now the top one being displayed when the tableview is again displayed.
My question is this: can I just call [myTableVC.tableView scrollToRowAtIndexPath:someIndex] from inside the other class when the button is pushed? Or does the view actually have to be on the screen when scrollToRowAtIndexPath is called for it to change the top cell that will be displayed?

You may be able to, but you probably shouldn’t—calling view or tableView on an offscreen view controller may cause its view to get loaded into memory unnecessarily. Just set a property—a CGFloat or whatever—on the view controller for the scroll position that it should be at when it appears, and scroll to that position in the controller’s -viewDidLoad or -viewWillAppear:animated:.

Related

Scroll View Edit - can I edit it outside of the view controller?

I'm a newbie here,
While editing scroll view contents on XCode 4's storyboard, you have to drag back and forth to "peek" and edit contents withint the view controller of iphone screen size.
Is there a way to directly edit scroll view content outside, so I don't have to constantly shift is carefully back and forth? Drying me crazy now :)
Thanks!
You can also drag the scroll view content (which should be a single UIView or its subclass) out of the scroll view by selecting in the view hierarchy tree on the left of the storyboard editor (should be the only view that is a subview of the scroll view) and dragging it to, say, the top of the list to be on the same level (leftmost) as the root view (which should be the topmost item in that hierarchy). Then, you can select your content view. It should appear in the storyboard. When you are done editing it, drag it back below the scroll view in the view hierarchy list (it becomes the scroll view's content view at that point).

How to get the animation right: inputView from a UINavigationController's nav bar?

I have a custom UIControl subclass with a UIPickerView as inputView. When the control is tapped, it calls becomeFirstResponder and the picker view automatically slides up from the bottom of the screen, like the system keyboard. This is working great!
The problem is that I am using the custom control as the titleView of a UINavigationItem. It functions properly, but if the view controller is popped off the navigation controller stack while the picker view is visible, the animation is wonky.
What I want to happen:
everything is pushed off screen to the right at the same time
What actually happens:
first, the background view and navigation bar slide off screen, the picker remains in place
then, after they are gone, the picker slides off to the right also
When I use the custom control inside the view controller's main view, it animates away just like the standard keyboard. So it seems as though this is a function of "coming from" the navigation bar, which is animated separately from the views inside.
How can I fix this, so that the inputView slides out with the rest of the content?
Turns out this can be fixed by calling endEditing: on the UINavigationController's view. In other words, within a view controller:
[self.navigationController.view endEditing:YES];
This causes the input view to slide down while the rest of the view slides off to the right. Not exactly the same as the system keyboard, but not obviously weird.

iPhone iPad UIView controller popup centered

My application is for iPad.
I have a UIViewController as the main view of my application.
I have an UIView at the bottom as a footer, and inside 3 UIView (subviews).
My 3 subviews in the footer banner load for each a different UIViewController and display the view of this controller into their view.
I would like when I click on a button into one of this subview (button that belongs to my UIViewController, with a 240x162px view), to make the subview disappear and display a centered popup (500x350px) with an animation into my main view.
To show you an example, WeatherBug for iPad has what I want, when you click on a block on top, the little view flip and a zoom effect is done, that display a centered uiview with more content.
Please tell me where I should look for!
Thank you,
Use the delegate pattern. Assign your "root" view controller as the delegate for your "footer" view controller. When the button is tapped (no clicking on the iPhone), the "footer" view controller will hide the banner, then call a delegate method to handle the tap action; in this case, the "root" view controller then shows your centered popup. When the popup is done, the "root" view controller then tells the "footer" view controller go show the banner again and go back to normal.

Why isn't my UITableView appearing in the correct scroll position?

I have a split view-based app that presents a master-detail interface, and uses a popover to present the master list when in portrait mode. The popover presents a sectioned table view that ultimately gets populated by a subclass of NSFetchedResultsController. I can tap the tool bar button to present the master list, scroll to whatever row, and tap the row to dismiss the popover.
My problem is that if the table is scrolled past the top of the second section, when I dismiss the popover and then later tap the toolbar button to re-present it, the table's scroll position is always set such that the first row of the second section is at the top of the list. If I haven't scrolled past the top of the second section, it correctly remembers its scroll position when the table is presented again.
Similarly, in landscape mode, if I scroll the table past the top of the third section and then rotate to portrait, when I come back to landscape the scroll position is always set such that the first row of the third section is at the top of the list.
I tried calling -scrollToNearestSelectedRowAtScrollPosition:animated in both the master view controller's -viewWillAppear, as well as in the split view delegate's splitViewController:popoverController:willPresentViewController:, to no effect. Anybody have a clue what I might be doing wrong?
Did you try storing tableView.contentOffset?
CGPoint offset = tableView.contentOffset;
...
...
...
[tableView setContentOffset: offset];

How to add a view above my NavigationControllers TableView

I have created a reusable class that fades in a "loading message" and indicator at the foot of the devices screen.
The problem I have is that when I'm adding the loadingview to a view that is contained in a NavigationController I want the view to stay at the bottom of the screen, even when scrolling the tableview.
How can i add a view ABOVE the TableView that is not affected by scrolling and such?
Add it to the view containing the UITableView so that it is a peer to the UITableView rather than a child of it. Generally, this is the UIWindow that your application delegate owns.