This shows you the differences between two versions of the page.
objective-c:examples:uiwebview_using_local_resources [2014/08/19 01:03] Mo |
objective-c:examples:uiwebview_using_local_resources [2024/02/16 01:06] (current) |
||
---|---|---|---|
Line 5: | Line 5: | ||
If you're following this example it is necessary that you are familiar with XCode and UIWebView-Basics. | If you're following this example it is necessary that you are familiar with XCode and UIWebView-Basics. | ||
- | First we will create the project. Open up XCode and click File->New->Project. Single View Application is the template we want for this purpose. Select it and click next. Now provide a name for your project. I named mine 'UIWebViewSample'. | + | First we will create the project. Open up XCode and click File->New->Project.\\ |
+ | {{:objective-c:examples:bildschirmfoto_2014-08-18_um_22.30.57.png}}\\ | ||
+ | Single View Application is the template we want for this purpose. Select it and click next. Now provide a name for your project. I named mine 'UIWebViewSample'. | ||
In the ViewController.m and make your interface declaration at the top look like this: | In the ViewController.m and make your interface declaration at the top look like this: | ||
Line 102: | Line 104: | ||
So now we need to go to the Interface-Builder or Storyboard and add a UIWebView and UIBarButtonItem. If you are not using Storyboard it is enough to add a UINavigationBar and on it place the UIBarButtonItem. If you are working with Storyboard add a UINavigationController and make the ViewController the initial(RootViewController) ViewController of the UINavigationController. This will cause that a UINavigationBar gets added to the ViewController. Add the UIBarButtonItem on it. | So now we need to go to the Interface-Builder or Storyboard and add a UIWebView and UIBarButtonItem. If you are not using Storyboard it is enough to add a UINavigationBar and on it place the UIBarButtonItem. If you are working with Storyboard add a UINavigationController and make the ViewController the initial(RootViewController) ViewController of the UINavigationController. This will cause that a UINavigationBar gets added to the ViewController. Add the UIBarButtonItem on it. | ||
- | We created two IBOutlets(webView and backBarButton), connect them with the objects we just added to the view. Do not forget to connect the delegate of the UIWebView to the ViewController. | + | We created two IBOutlets(webView and backBarButton), connect them with the objects we just added to the view. Do not forget to connect the delegate of the UIWebView to the ViewController.\\ |
+ | {{:objective-c:examples:bildschirmfoto_2014-08-19_um_01.34.49.png}}\\ | ||
- | The last thing to do is add some resources. | + | The last thing to do is add some resources.\\ |
- | Right-click or ctrl-click on a group or folder. In the pop-up click new file->other and create the following files. | + | Add an image. Mine is vmax.jpg.\\ |
+ | {{:objective-c:examples:vmax.jpg}}\\ | ||
+ | Right-click or ctrl-click on a group or folder. In the pop-up click new file. Select iOS:Other->Empty and create and name like the following. Repeat and copy-paste below code to each file. | ||
=== index.html === | === index.html === | ||
Line 253: | Line 258: | ||
} | } | ||
</code> | </code> | ||
+ | |||
+ | To make the Javascript part work one more thing is necessary:\\ | ||
+ | {{:objective-c:examples:buildphases.png}}\\ | ||
+ | Click on the blue project icon at the top of the project-navigator on the left and then under targets select the target with name of your project. Find 'Build Phases' and add the main.js to 'Copy Bundle Resources' while clicking add(+) and select your .js file. And that's it!\\ | ||
+ | |||
+ | Run the project and you should see somethings like this. A Javascript call and the index.html after closing the alert:\\ | ||
+ | {{:objective-c:examples:jscall.png}}{{:objective-c:examples:indexcontent.png}}\\ | ||
+ | I hope this will help somebody somehow. Took me a while to figure this small amount of how-to out. Happy coding :) |