This shows you the differences between two versions of the page.
objective-c:examples:uiwebview_using_local_resources [2014/08/19 01:40] Mo |
objective-c:examples:uiwebview_using_local_resources [2024/02/16 01:06] (current) |
||
---|---|---|---|
Line 6: | Line 6: | ||
First we will create the project. Open up XCode and click File->New->Project.\\ | 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}} | + | {{: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'. | 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'. | ||
Line 104: | 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}} | + | {{: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.\\ | ||
- | Add an image. Mine is vmax.jpg. | + | Add an image. Mine is vmax.jpg.\\ |
- | {{:objective-c:examples:uiwebview using local resources: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. | 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. | ||
Line 259: | Line 259: | ||
</code> | </code> | ||
- | To make the Javascript part work one more thing is necessary: | + | To make the Javascript part work one more thing is necessary:\\ |
- | 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! | + | {{: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 :) | I hope this will help somebody somehow. Took me a while to figure this small amount of how-to out. Happy coding :) |