Search code examples
xcodeuiwebviewbookmarks

Creating Bookmarks


Today I'm working with an interesting problem. I'm trying to code simple bookmarks, and by that I mean the most basic functionality; store the url, and load the url when you tap it.

Right now, the idea is that I would use the following:

currentURL = currentWebView.request.URL.absoluteString;

To retrieve the current URL, and then possibly store that within NSDefaults. (Open to any other suggestions on better ways of preforming this)

However, the problem that I'm having is that, assuming I've gotten that far (retrieved the URL and stored it), how would I go about putting then somewhere in a list format that displays the url that was bookmarked, and then loading them (from that separate bookmarks view) in the main view that the UIWebView is contained in?

Your time is much appreciated --Jake

NOTE: If you need more information or anything I could possibly help you with in order to come to a solution, just ask


Solution

  • Simple

    Suppose your viewcontroller where your webview resides, is WebViewController and where list shows is BookmarkViewController.

    Create a property in BookmarkViewController

    @property(nonatomic,retain)WebViewController *maincontroller;
    

    Send the reference of your WebViewController to BookmarkViewController when you create BookmarkViewController object

    bookmarkobject.maincontroller=self;
    

    and then In didSelectRowAtIndexPath

    either use

    1) [maincontroller.webView loadRequest:url];

    or

    make a method in WebViewController with parameter url and call this method from didSelectRowAtIndexPath

    2) [maincontroller loadUrlInWebView:url];

    and dismiss your modal

    or create a property of url in WebViewController and in didSelectRowAtIndexPath

    3) [maincontroller urlstring:url]; and in viewWillAppear load this url in your webview

    Hope any of these 3 methods will help you.