andreamazz / AMScrollingNavbar

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
MIT License
6.05k stars 633 forks source link

What if no IBOutlet? #23

Closed bobi33 closed 10 years ago

bobi33 commented 10 years ago

What if I programatically made a UITableViewController. There is no View where I can connect an IBOutlet for tableView, therefore

[self followScrollView:self.tableView]; --> will not work for me... how can I call this method in my case?

andreamazz commented 10 years ago

Create an instance of AMScrollingNavbarTableViewController instead of UITableViewController and call this:

[yourTableViewController followScrollView:yourTableViewController.tableView];
bobi33 commented 10 years ago

Thanks.

Also, setting up without cocoapods gives this error: No visible @interface for WebViewController declares the selector 'followScrollView'

andreamazz commented 10 years ago

Is your WebViewController a subclass of AMScrollingNavbar?

bobi33 commented 10 years ago

Thanks, that was the issue. Everything works fine except that when I use the following method it only scrolls to the the top of the screen, but doesn't show the navigation bar. :

-(BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {

// This enables the user to scroll down the navbar by tapping the status bar.
[self showNavbar];

return YES;

}

andreamazz commented 10 years ago

What view controller are you trying to scroll to top? Is it the tableviewcontroller that you created programmatically? In that case you need to call showNavbar on its instance.

bobi33 commented 10 years ago

It's actually a WebViewController.

andreamazz commented 10 years ago

Ok, so your self is the instance of your WebViewController, which subclasses AMScrollingNavBar, is this correct?

bobi33 commented 10 years ago

Yes.

andreamazz commented 10 years ago

Ok, got it. Add this line to your webviewcontroller:

    self.webView.scrollView.delegate = self;

Checkout the sample in the latest commit for more info

bobi33 commented 10 years ago

Hey, that seems to fix the issue with the navigation bar reappearing, however it causes other issues for me...

It causes an issue with the web view fitting in the view controller. What I mean by this is that webviewcontroller ends up moving up the page, not fitting correctly on the view. This causes the web view to shift up 60px, which causes the top of the web view to be hidden by the navigation bar that reappears.

andreamazz commented 10 years ago

Try the latest code in commit fc84dbb, I made a small change in the showNavbar method.

bobi33 commented 10 years ago

I copied the latest code. It fixes the issue of shifting the webView up, however, because the webView is apart of a navigation controller when I go back two pages to the initial navigation view controller page ("Home Page"), that viewController becomes shifted down by about 80px.

andreamazz commented 10 years ago

You have to give me more details, I can't recreate the issue right now.

bobi33 commented 10 years ago

Ok, so I'll explain my setup:

-I have a navigationController setup like this... -user presses a UITableViewCell in ViewController1, which takes them to ViewController2; -user presses a UITableViewCell in ViewController2 and it takes them to ViewController 3; -user presses a UITableViewCell in ViewController3 and it takes them to the WebView; -the WebView works fine in terms of the scrolling issue I previously told you about; -However, when the user presses back on the NavigationBar and ends up on ViewController2, there seems to be an 80px shift of the view downwards (so there is a white gap of about 80px right underneath the navigation bar).

andreamazz commented 10 years ago

That's weird, it's not that different from the sample project, that doesn't suffer from this issue. I also tried to reproduce the same structure (table->table->web) and I can't reproduce the issue. I suggest to check out the sample project and make sure that everything is properly configured.

bobi33 commented 10 years ago

Yeah it is weird. I will take another look at it...maybe I forgot to mention that ViewController3 is a UISearchBar and Display Controller.

andreamazz commented 10 years ago

That might be it, I haven't tested the control with a display controller yet.

bobi33 commented 10 years ago

Oh ok. Well if you do could you please let me know. Thanks for the help.

bobi33 commented 10 years ago

I've been really troubleshooting this issue to see if it's on my end and can't seem to find anything...

andreamazz commented 10 years ago

I updated the sample project, now it contains a searchbar with a display controller. It seems to work just fine. Just make sure to use autolayout.

bobi33 commented 10 years ago

Thanks. I tried the new project, however I can't understand why it is conflicting with mine. I still get that gap when I push back from the web view to ViewController2. I don't know if it has something to do with my setup. It shouldn't. However, I'm using ECSlidingViewController as my setup, so maybe it's conflicting with that?

andreamazz commented 10 years ago

That might be it, though I never tried that control, since I have my own implementation of a sliding view controller.

bobi33 commented 10 years ago

Ahhhh ok. That's unfortunate. I'm too invested in that control to change now lol. Thanks Andrea for your help. If you ever try that control keep me posted.