Segue/Navigate to View Controller from UIWebView - ios

I have a webview on view controller that load a page consist of list of item.
If I click on each item, I want to navigate into spesific view controller and bypass an id from item's link.
Right now I have no clue how to do this. Is this even possible?
Any help would be appreciated. Thank you.

Yes, this is entirely possible. You need to use a URL Scheme to communicate from JavaScript to native code.
A URL Scheme allows you to pass data from JavaScript to native code like this:
window.location = 'yoururlscheme://somehost?greeting=hello'
You receive this event using UIWebViewDelegate, where you can fire a segue, or whatever you want.
See this answer for details: https://stackoverflow.com/a/36144481/1305067

Related

delegate equals to nil

I have a problem with my iconMenu it doesn't work, I can only slide to open my menu, I have this error only I change page from my first page ("Accueil") instead of using my slide out menu. Yes because I have a slide out menu and links on my first page, like that:
So when I use links of my first view, my iconMenu is like disabled, it's because here:
#IBAction func menuNosOffresTapped(sender: AnyObject) {
delegate?.toggleLeftPanel!()
}
My app can't go at the function toggleLeftPanel here: Call a function of an another class (protocol) someone told me that the problem could came from my delegate.
I did some test, I lost my delegate when I use first page links and when I use my Slide out menu.
App is here: https://github.com/Vkt0r/SlideOutSideBarTest
So I think to get access to toggleLeftPanel, I have to get my delegate.
the problem is your NosOffresViewController is missing the menuTapped action.

How to replace content ViewController inside other View controller

I am working on an application which allows users to work with a couple of workmodes. Main view of the app contains information common to all workmodes. I want to create a "subview" with ability to change its ViewController. This subview will be used to display information connected with specified workmode. It is important that app goes to MainViewController from WorkmodesViewController in which user chooses workmode to work with.
My question is:
Which tehnique should I use to acheave changeable WorkmodeViewController inside MainViewVontroller
I have found example git project with functionality I need:
https://github.com/mluton/EmbeddedSwapping

jump to next view without navigation-based app

What ways are there to change views other than using a navigation-based app? I want my first view to be basically just a simple form and when the user hits a "submit" button I want to send him over to the main view, without being able to return. And I don't want the bar on the top of the view either.
How can I achieve this, and if possible without losing the animations that come with a navigation-based app.
If you wanted your app to be entirely navigation controller free, you can use one of the signatures of presentModalViewController:animated: from whichever UIViewController you deem best fit to be the parent. Call [self dismissModalViewControllerAnimated:YES] on the child view (form you want submitted) after you've handled state change on submit. One thing to watch out with this, is as of iOS 5, Apple now prefers that you use presentViewController: instead, and presentModalViewController: is marked for deprecation at a future date.
In terms of "how you would know the user submitted the form, so they may now proceed in your application" - one way you could do that is to use delegation / notifications to maintain awareness of the state of the form. When the child form is submitted, you can call the parentViewController's delegate callback to set flags - or return authentication data, for example - in your AppDelegate or some high-level class. Delegation and Notifications are useful tools when using the iOS SDK.
Option two could be using a completion handler in with your call to present the child, such as:
ChildForm *childFormWithSubmit = [[ChildForm alloc] init];
[self presentModalViewController:childFormWithSubmit animated:YES
completion:^(/*inlineFunctionParams*/)
{ /*inlineFunctionBodyToRunOnCompletion*/ }];
Lots of possibilities ~
Did you look at 'presentViewController:animated:completion:' in the UIViewController class description? There are lots of options for how you animate in another viewController.
Sled, you can simply just hide the UINavigationBar for your UINavigationController.
That way you won't see the UINavigationBar and the user will not be able to return back to that page.
You'll need to set a permanent flag in your app either writing to text file or using NSUserDefaults.

Getting WebView AbsoluteString In Second View

I'm in need of some detail. I've looked through multiple books/forums, and I've tried as best as I can on my own. However, at this point I'm in need of some outside help with simple directions, if at all possible. I'm trying to make this as easy as possible to get the goal across, and if you need anything, just ask.
So, here is what I'm trying to do:
What I have:
I currently have the WebView view, and the bookmarks view with a table in it. I have NSUserDefaults passing the current URL to the bookmarks view and displaying it (but not saving it)
What the goal is:
I need to add an "Add Bookmarks" button underneath the rest of the table that gets the current string of the WebView in the other view and saves it as an entry to the table.
What I need:
So, at this point (as a start) I need a method of getting the URL of the WebView from the other view and transferring it to the bookmarks view to be saved as a row to the table.
I was thinking of doing this by calling absoluteString and saving to user defaults, but I need assistance for the code portion. I don't know the full usage of NSUserDefaults yet, but I do have some experience with it.
Thanks for the help! It's greatly appreciated!
Jake
You should pass the current URL and Title to the Bookmarks view before you open it:
[bookmarks setUrl:webView.request.URL.absoluteString];
[bookmarks setTitle:[webView stringByEvaluatingJavaScriptFromString:#"document.title"]];
... open bookmark view now ...
A full example would be:
- (IBAction)bookmarksPressed:(id)sender {
// Open the book marks controller passing it the current URL and Title
BookmarksViewController * bookmarksViewController = [[[BookmarksViewController alloc] initWithNibName:#"BookmarksViewController" bundle:nil] autorelease];
[bookmarksViewController setUrl:webView.request.URL.absoluteString];
[bookmarksViewController setTitle:[webView stringByEvaluatingJavaScriptFromString:#"document.title"]];
[self presentModalViewController: bookmarksViewController animated:YES];
}

Is is possible to communicate between UINavigationController and web page loaded inside UIWebView?

I am new to iOS development. I will try my best to explain my question, please pardon me if you find it silly.
I was wondering if one can load a subview in a UINavigationController by clicking a link inside a UIWebView.
Explaining it further, let's say there is UINavigationController that has a subview and that subview has a UIWebView called A, and there is another subview(that is not loaded yet) called B. Is is possible to load B (or perform any other native Objective C event) when user taps on a link inside the UIWebView A?
For example in Instagram app for iPhone, as I have observed (I may be wrong), there are UIWebViews in views controlled by UINavigationControllers. Taping a link inside a web view loads a new view. How is it happening? Can one set up the communication between the web page loaded inside the UIWebView and the parent/super UIView?.
Please correct me if I am lost. I am a n00b in iOS development so far. Also reference me the APIs or tutorials to do this if this makes any sense. Thanks in advance.
If you want just to handle a click-on-link inside UIWebView, just implement a delegate for the UIWebView. It has webView:shouldStartLoadWithRequest:navigationType: , which is called any time any content is attempted to be loaded in UIWebView. In the implementation of this method, you can block loading of the HTML content and perform any obj-c code, you want.
Hope that helps!

Resources