-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRCWebViewController.m
More file actions
149 lines (120 loc) · 3.87 KB
/
RCWebViewController.m
File metadata and controls
149 lines (120 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// RCWebViewController.m
// PageControl
//
// Created by rcrebs on 1/13/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "RCWebViewController.h"
#import "AppDelegate.h"
@implementation RCWebViewController
@synthesize delegate, url, webView;
@synthesize backButton, forwardButton, safariButton;
@synthesize safariLoadIndicator;
@synthesize buttonItem;
@synthesize webViewNavBar, navTitle;
//@synthesize webViewToolBar;
#pragma mark -
#pragma mark ActionMethods
-(IBAction)done {
// Takes the image of RCWebViewController's delegate, and all this method for the delegate to then execute.
[self.webView stopLoading];
[self.delegate webViewControllerDidFinish:self];
}
-(IBAction)back {
[self.webView goBack];
}
-(IBAction)forward{
[self.webView goForward];
}
-(IBAction)openInSafari {
UIActionSheet *usageActionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Go to Safari", nil];
[usageActionSheet showInView:[AppDelegate sharedAppDelegate].view];
//[usageActionSheet showFromToolbar:self.webViewToolBar];
//[usageActionSheet showFromBarButtonItem:buttonItem animated:YES];
}
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
#pragma mark -
#pragma mark UIWebViewDelegate methods
- (void)webViewDidStartLoad:(UIWebView *)webView {
// Show and start UIActivityIndicatorView
[self.safariLoadIndicator startAnimating];
self.webView.scalesPageToFit = YES;
// Check if back forward buttons are clickable for user
if ([self.webView canGoBack]) {
backButton.enabled = YES;
}
else {
backButton.enabled = NO;
}
if ([self.webView canGoForward]) {
forwardButton.enabled = YES;
}
else {
forwardButton.enabled = NO;
}
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[self.safariLoadIndicator stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
}
#pragma mark -
#pragma mark UIActionSheetDelegate Methods
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// buttonIndex 1: cancel button clicked
// buttonIndex 0: Go to safari button clicked
switch (buttonIndex) {
case 0:
[[UIApplication sharedApplication] openURL:self.url];
break;
}
}
#pragma mark -
#pragma mark Other Delegate Methods
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
// Get navigation bar items
NSArray *navItems = webViewNavBar.items;
// get the tile item
UINavigationItem *navigationBarTitleItem = [navItems objectAtIndex:0];
// set the title to the image title
navigationBarTitleItem.title = navTitle;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end