English 中文(简体)
scrollsToTop doesn t work when UIWebView used with pushViewController, looking for solution
原标题:

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?

最佳回答

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 :)

问题回答

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!





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签