-
-
Save cactis/10088874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Here's the same thing in Objective-C | |
#import "WebView.h" | |
@implementation WebView | |
@synthesize webView = _webView; | |
-(void) viewDidLoad | |
{ | |
[super viewDidLoad]; | |
UIWebView *webview = [[UIWebView alloc] init]; | |
webview.autoresizingMask = UIViewAutoresizingFlexibleWidth; | |
[self.view addSubview:webview]; | |
self.title = @"Web View"; | |
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"WebView" ofType:@"html"]; | |
[_webView loadHTMLString:[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil] baseURL:nil]; | |
_webView.delegate = self; | |
} | |
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType | |
{ | |
if ( inType == UIWebViewNavigationTypeLinkClicked ) | |
{ | |
[[UIApplication sharedApplication] openURL:[inRequest URL]]; | |
return NO; | |
} | |
return YES; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WebViewController < UIViewController | |
def viewDidLoad | |
super | |
self.title = "Web View" | |
self.view = UIWebView.alloc.init | |
view.delegate = self | |
webviewContent = File.read(App.resources_path + "/WebView.html") #This requires Bubble-Wrap to be installed | |
self.view.loadHTMLString(aboutContent, baseURL:nil) | |
end | |
#Open UIWebView delegate links in Safari. | |
def webView(inWeb, shouldStartLoadWithRequest:inRequest, navigationType:inType) | |
if inType == UIWebViewNavigationTypeLinkClicked | |
UIApplication.sharedApplication.openURL(inRequest.URL) | |
false #don't allow the web view to load the link. | |
end | |
true #return true for local file loading. | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment