views:

377

answers:

2

I have an app with a table view at the root in a navigation controller, and on selection of a table cell it displays a new view controller that contains only a UIWebView (with a toolbar and a navbar).

Depending on how I present the new web view, the feature where the user can tap on the status bar at the top and have the webview scroll to the top, either works or doesn't work.

If I use:

  • (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated

on the RootView, then the webview does scroll to the top.

If I change that one line of code and instead use:

  • (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

on the navigation controller, then the scrollsToTop feature stops working.

What I really want to use however, for other reasons in the context of the app, is the pushViewController method. BUT, I also want to keep the scrollsToTop behaviour.

I have so far tried various approaches, some described here:

-Attempting to set the webview internal scrollView scrollsToTop property

((UIScrollView *)[[webView valueForKey:@"_internal"] valueForKey:@"scroller"]).scrollsToTop = YES;

(No discernible effect).

-Changing the ordering of setting NavBar properties or not setting any at all -Adding extra "window makeKeyAndOrderFront" calls after the new view push.

I don't believe there are other views there that could be claiming the "scrollsToTop" property (and the first test above proves that in any case).

Short of attempting to embed UIWebView into a UIScrollView, which I expect will be painful, I have run out of routes to explore to resolve this issue.

I am hoping someone else has found a way to correct this?

A: 

Try the reverse approach as a workaround.

In the root view controller:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.tableView.scrollsToTop = NO;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tableView.scrollsToTop = YES;
}

Bye!

muccy
Thanks for the response muccy! I see where you are going there, perhaps the root view with its table is claiming the scrollsToTop! With high hopes I tried this, but unfortunately no effect! :-(Many thanks for the idea though, and if you have any others, don't hesitate to throw them over :)
theLastNightTrain
It's really strange.In an app I'm developing I have the same scenario (table view controller -> web view [controller]) and I have no issues with the status bar behaviour...If I'll have an idea I won't hesitate to suggest you! :)
muccy
A: 

It turns out that it wasn't working because of the way I was customiing the Navbar. I was overriding leftBarButtonItem with a UIBarButtonItem that then took up the whole navbar (I think I took that approach from some Apple code many months ago, but not sure). I was using the same approach on another view and the scrollsToTop worked fine there.

Taking that code out and putting the custom Navbar view into (eg)self.navigationController.titleView instead solved this problem. I do not really know why, like I say it works fine for other views.

I wasted a lot of time with this problem, so I hope I save someone else some hair by describing it here :)

theLastNightTrain