Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:35:39+00:00 2026-06-16T01:35:39+00:00

I have a webView-based app, but I want the user to be able to

  • 0

I have a webView-based app, but I want the user to be able to navigate it with swiping on the trackpad and magic mouse. Therefore, I am going to implement NSPageController.

I have looked at the documentation and the PictureSwiper app, however those aren’t really meant for a webView. So, I would like to know how I can use an NSPageController on a webView. I have a webView defined as webView and two actions, goBack: and goForward: that load the previous and next page respectively.

However, I am unaware of how I get NSPageController to work with a simple webView. There has a to be a way to do it, but I see no way. If someone could please explain what I am suppose to do, that would be great. Or if you are feeling especially generous, you can download my free browser source example. https://sites.google.com/site/infiniteopensyntax/basic-web-browser

That source shows how my own app is pretty much set up. If you would like to implement the NSPageController on that app and send me the source, I would really appreciate it. It’s not much, but if you do that I’ll add the swiping example to Infinite Open Syntax and put your name on it. You can choose the license.

This is Cocoa, not Cocoa Touch

EDIT

Okay, now I just need to make sure the app still works on Snow Leopard. Supposedly, I can test this by disconnecting the outlets. It works fine, minus the back and forward button. To do this, I believe I check for the class NSPageController. If it doesn’t exist, then I just skip using the pageController.

- (IBAction)goBack:(id)sender {
    if (NSClassFromString(@"NSPageController") != Nil)
    {
        [self.pageController navigateBack:sender];
    }
    {

         //Not 10.8
        [webView goBack];
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:35:40+00:00Added an answer on June 16, 2026 at 1:35 am

    The download link on the page you linked to doesn’t work, so I’ll keep my answer more general.

    You don’t need to keep multiple WebViews or manually generate snapshots if you’re using NSPageController; it takes care of that for you. In your case, you want to use NSPageController in History Mode. To do that, wire your WebView to pageController.view. You will need to implement three NSPageControllerDelegate methods:

    - (void)pageControllerWillStartLiveTransition:(NSPageController *)pageController;
    - (void)pageController:(NSPageController *)pageController didTransitionToObject:(id)object;
    - (void)pageControllerDidEndLiveTransition:(NSPageController *)pageController;
    

    Every time the WebView goes to a new page (not through a back/forward action), call navigateForwardToObject:(id)object on the pageController. I would make object a custom object that stores user state for a navigated page (scroll positions, highlighted text, form contents, etc.) as well as the page’s WebHistoryItem. The user state can be undefined initially, but should get set in pageControllerWillStartLiveTransition:. Here’s an example:

    - (void)pageControllerWillStartLiveTransition:(NSPageController *)pageController
    {
      // Remember user state
      MyCustomObject *object = [self.pageController.arrangedObjects objectAtIndex:self.pageController.selectedIndex];
      object.userState = someUserState;
    }
    

    When that method returns, the pageController will hide its view (the WebView) and display snapshots of previous states of its view instead.

    Once the swiping animation is complete, pageController:didTransitionToObject: will get called. Cool. What you should do in that method is grab the WebHistoryItem out of object and have the WebView go back to that item using the goToBackForwardItem: method. You should also hold onto the user state you stored in object (say, in an instance variable), because you’ll need to restore it once WebView finishes loading.

    Lastly, in pageControllerDidEndLiveTransition: you do anything you want done before redisplaying the WebView. I expect that would be nothing, since the user state isn’t restored until the WebView finishes loading, so all you would need in its implementation would be [pageController completeTransition].

    One last detail is the back/forward buttons. You should implement them as you would normally, but also have them call navigateBack: or navigateForward: on the pageController.

    That pretty much covers it. I haven’t actually tried this specific example, so let me know if you run into any problems.

    Edit

    Here’s how I’d modify your source to get basic NSPageController functionality. Add an NSPageController IBOutlet property in your AppDelegate header file. In your MainMenu.xib file add the page controller, wire its view to your WebView, make your AppDelegate its delegate, and give it a referencing outlet to the property we just created in the AppDelegate. Also, make your AppDelegate your WebView’s frameLoadDelegate. Inside basicWebAppDelegate.m add a private property:

    @interface basicWebAppDelegate ()
    @property (assign) id currentItem;
    @end
    

    Then add the following inside implementation:

    #pragma mark - WebFrameLoadDelegate
    
    - (void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
      if (frame == [sender mainFrame]) {
        id object = [sender.backForwardList currentItem];
        BOOL isCurrentItem = self.currentItem && (object == self.currentItem) ? YES : NO;
        if (!isCurrentItem) {
          [self.pageController navigateForwardToObject:[sender.backForwardList currentItem]];
        }
      }
    }
    
    
    #pragma mark - NSPageControllerDelegate
    
    - (void)pageControllerWillStartLiveTransition:(NSPageController *)pageController {
      self.currentItem = [self.webView.backForwardList currentItem];
      // Here is where you'll save any state for your pageController.arrangedObjects[pageController.selectedIndex] object
    }
    
    - (void)pageController:(NSPageController *)pageController didTransitionToObject:(id)object {
      BOOL isCurrentItem = self.currentItem && (object == self.currentItem) ? YES : NO;
      if (!isCurrentItem) {
        self.currentItem = object;
        [self.webView goToBackForwardItem:object];
      }
    }
    
    - (void)pageControllerDidEndLiveTransition:(NSPageController *)pageController {
      self.currentItem = nil;
      [pageController completeTransition];
    }
    

    Finally, change your goBack: and goForward: actions to just call [self.pageController navigateBack:sender] and [self.pageController navigateForward:sender], respectively.

    Note that I didn’t bother saving any user state here and instead used WebHistoryItems directly as the objects. You might need to do differently.

    Let me know if you need more help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webview and I want to manually switch to another tab during
I have a WebView. I'd like to show some page from my server, but
I have a webview, which shows the pages of a ebook. I want to
I am new to iphone development.I have created a view based application.Now i want
I have a simple WebView-based activity that follows the Hello, WebView example to enable
I have a view based application and in that I want to show driving
I have a web based application that uses Cocoa/CocoaTouch's UIWebView. I want (need?) to
I'm trying to build an app (first one) that has webview. I have used
In a doc-based ARC-enabled application I have a WebView that is opening an HTML
I have a WebKit-based application. When the user initiates an action that opens a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.