In my app I've a view controller in which there are a table view, when I tap on one of table view row it should dismiss the actual view controller an pass back an url to load it in a web view. I thought the right way to do that it's to implement a delegate, so I did it but when I try to run the app when I tap on the row of table view it doesn't call the delegate method.
I add here some code to understand what's wrong:
HistoryNotificationViewController.h
#import <UIKit/UIKit.h>
#protocol HistoryNotificationDelegate;
#interface HistoryNotificationViewController : UIViewController
#property(nonatomic,weak) id <HistoryNotificationDelegate> delegate;
#end
#protocol HistoryNotificationDelegate <NSObject>
- (void) updateWebViewWithURL:(NSString*)url;
#end
HistoryNotificationViewController.m (I post only the method in which I call the delegate method)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.delegate updateWebViewWithURL:[sortedArray[indexPath.row] objectForKey:#"url"]];
[self dismissViewControllerAnimated:YES completion:nil];
}
HomeViewController.m (view controller that should implement the delegate method of HistoryNotificationViewController.m)
#import "HomeViewController.h"
#import "SSKeychain.h"
#import "SSKeychainQuery.h"
#import "MBProgressHUD.h"
#import "HistoryNotificationViewController.h"
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#interface HomeViewController () <UIWebViewDelegate, HistoryNotificationDelegate>
#property (weak, nonatomic) IBOutlet UIWebView *webView;
- (IBAction)buttonForward:(UIButton *)sender;
- (IBAction)buttonBack:(UIButton *)sender;
#property(nonatomic,strong)MBProgressHUD *hud;
#end
#implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.hud = [[MBProgressHUD alloc]init];
self.hud.labelText = #"Loading";
self.hud.mode = MBProgressHUDModeIndeterminate;
[self.view addSubview:self.hud];
NSURL *url = [[NSURL alloc]init];
NSURLRequest *request = [[NSURLRequest alloc]init];
if (!self.website) {
url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:#"website" ]];
request = [NSURLRequest requestWithURL:url];
} else {
[[NSUserDefaults standardUserDefaults] setObject:self.website forKey:#"website"];
[[NSUserDefaults standardUserDefaults] synchronize];
url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:#"website"]];
request = [NSURLRequest requestWithURL:url];
}
[self.webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
HistoryNotificationViewController *historyNotificationViewController = [[HistoryNotificationViewController alloc]init];
[historyNotificationViewController setDelegate:self];
}
#pragma mark HistoryNotificationDelegate
- (void)updateWebViewWithURL:(NSString *)url {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.webView loadRequest:request];
}
#pragma mark UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView {
[self.hud show:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self.hud hide:YES];
}
- (IBAction)buttonForward:(UIButton *)sender {
[self.webView goForward];
}
- (IBAction)buttonBack:(UIButton *)sender {
[self.webView goBack];
}
#end
What's wrong in my classes? Why it doesn't execute the delegate method?
Try this,
Make a property for HistoryNotificationViewController by
#property (nonatomic, strong) HistoryNotificationViewController *historyNotificationViewController;
and in prepareForSegue :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destinationVC = [segue destinationViewController];
if ([destinationVC isKindOfClass:[HistoryNotificationViewController class]]) {
self.historyNotificationViewController = destinationVC;
[self.historyNotificationViewController setDelegate:self];
}
}
You need to get HistoryNotificationViewControllers in prepareForSegue from destinationViewController instead of allocating a new object...
#import "HomeViewController.h"
#import "SSKeychain.h"
#import "SSKeychainQuery.h"
#import "MBProgressHUD.h"
#import "HistoryNotificationViewController.h"
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#interface HomeViewController () <UIWebViewDelegate, HistoryNotificationDelegate>{
}
#property (weak, nonatomic) IBOutlet UIWebView *webView;
- (IBAction)buttonForward:(UIButton *)sender;
- (IBAction)buttonBack:(UIButton *)sender;
#property(nonatomic,strong)MBProgressHUD *hud;
#end
#implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.hud = [[MBProgressHUD alloc]init];
self.hud.labelText = #"Loading";
self.hud.mode = MBProgressHUDModeIndeterminate;
[self.view addSubview:self.hud];
NSURL *url = [[NSURL alloc]init];
NSURLRequest *request = [[NSURLRequest alloc]init];
if (!self.website) {
url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:#"website" ]];
request = [NSURLRequest requestWithURL:url];
} else {
[[NSUserDefaults standardUserDefaults] setObject:self.website forKey:#"website"];
[[NSUserDefaults standardUserDefaults] synchronize];
url = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] objectForKey:#"website"]];
request = [NSURLRequest requestWithURL:url];
}
[self.webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:#"YOUR_SEGUE_NAME_HERE_FOR_HISTORY_NOTIFICATION_VIEWCONTROLLER"])
{
// Get reference to the destination view controller
HistoryNotificationViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setDelegate:self];
}
}
#pragma mark HistoryNotificationDelegate
- (void)updateWebViewWithURL:(NSString *)url {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.webView loadRequest:request];
}
#pragma mark UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView {
[self.hud show:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self.hud hide:YES];
}
- (IBAction)buttonForward:(UIButton *)sender {
[self.webView goForward];
}
- (IBAction)buttonBack:(UIButton *)sender {
[self.webView goBack];
}
You do not need and should not use delegate at all in this case. Otherwise you're making thing complicated.
Just define a public method in your HomeViewController,
- (void)updateWebViewWithURL:(NSString *)url
{
}
Same method name as the one you've defined should be ok, but not as a delegate method!
Then, in your HistoryNotificationViewController.m, you'll be able to get a reference of HomeViewController easily. Something like this will do,
NSArray *viewControllers = self.navigationController.viewControllers;
HomeViewController *homeViewController = [viewControllers objectAtIndex:0];
[homeViewController updateWebViewWithURL:url];
Related
App description:
I want to develop an app, which shows websites during set time. If time elapsed, it will load next website etc. It must be run as loop: if last website showed, it shoes first.
AppDelegate was not changed.
Storyboard has a Navigation Controller with this ViewController, which include UIWebView:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UIWebViewDelegate>
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIWebView *mWebView;
#end
#implementation ViewController
NSMutableArray *mSites;
NSInteger mIndex;
- (void)viewDidLoad {
NSLog(#"%s", __PRETTY_FUNCTION__);
[super viewDidLoad];
mSites = [[NSMutableArray alloc] init];
[mSites addObject:#"http://www.bild.de"];
[mSites addObject:#"http://www.spiegel.de"];
[self setWebView];
mIndex = -1;
[self showNext];
}
- (BOOL)prefersStatusBarHidden
{
NSLog(#"%s", __PRETTY_FUNCTION__);
return YES;
}
- (void)setWebView
{
NSLog(#"%s", __PRETTY_FUNCTION__);
[(self.mWebView.subviews)[0] setBounces:NO]; // No overscroll
[self.mWebView setDelegate:self];
}
- (void)freeMemory
{
NSLog(#"%s", __PRETTY_FUNCTION__);
[self.mWebView loadHTMLString:#"" baseURL:nil];
[self.mWebView stopLoading];
[self.mWebView setDelegate:nil];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
}
- (void)webViewDidFinishLoad: (UIWebView *)webView
{
NSLog(#"%s", __PRETTY_FUNCTION__);
// Clear cache
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:#"WebKitCacheModelPreferenceKey"];
}
- (void)handleTimer: (NSTimer *)timer
{
NSLog(#"%s", __PRETTY_FUNCTION__);
[self freeMemory];
[self setWebView];
[self showNext];
}
- (void)showNext
{
NSLog(#"%s", __PRETTY_FUNCTION__);
// Loop
if (mIndex < [mSites count] - 1) {
mIndex++;
} else {
mIndex = 0;
}
NSString *site = [mSites objectAtIndex:mIndex];
NSURL *url = [NSURL URLWithString:site];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.mWebView loadRequest:request];
[NSTimer scheduledTimerWithTimeInterval:15
target:self
selector:#selector(handleTimer: )
userInfo:nil
repeats:NO];
}
- (void)didReceiveMemoryWarning
{
NSLog(#"%s", __PRETTY_FUNCTION__);
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
[self.mWebView reload];
}
#end
Trouble:
I use for testing iPad Air (A1474) and used two websites: http://www.bild.de and http://www.spiegel.de. After ca. 30 minutes crashes the app because of memory usage. The app use more than 300Mb.
I found more solutions to handle the memory leak trouble and integrate them in my code:
- (void)freeMemory
{
[self.mWebView loadHTMLString:#"" baseURL:nil];
[self.mWebView stopLoading];
[self.mWebView setDelegate:nil];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
}
- (void)webViewDidFinishLoad: (UIWebView *)webView
{
// Clear cache
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:#"WebKitCacheModelPreferenceKey"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
[self.mWebView reload];
}
But the solutions do not take effect. The app do not run longer than a hour.
Have somebody a solution how I can reach a app running time for at least a day for every?
Thanks in advance for suggestions.
I'm building a basic app for my school and can't figure out how to change the URL to be presented based on the button pressed. I have four buttons and currently have them all linked to temporary URLs, but when I run my app, the webview appears blank and my NSLog returns null for the URL. What am I doing wrong? Here is my code:
TWViewController.h:
#import <UIKit/UIKit.h>
#interface TWViewController : UIViewController
- (IBAction)gradesPressed:(id)sender;
- (IBAction)facPressed:(id)sender;
- (IBAction)newsPressed:(id)sender;
- (IBAction)sportsPressed:(id)sender;
#property (strong, nonatomic) NSURL *url;
#end
TWViewController.m:
#import "TWViewController.h"
#import "TWWebViewController.h"
#interface TWViewController ()
#end
#implementation TWViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)gradesPressed:(id)sender{
TWWebViewController *webView = [[TWWebViewController alloc] init];
webView.website = [NSURL URLWithString:#"http://google.com"];
}
- (IBAction)facPressed:(id)sender {
TWWebViewController *webView = [[TWWebViewController alloc] init];
webView.website = [NSURL URLWithString:#"http://yahoo.com"];
}
- (IBAction)newsPressed:(id)sender {
TWWebViewController *webView = [[TWWebViewController alloc] init];
webView.website = [NSURL URLWithString:#"http://facebook.com"];
}
- (IBAction)sportsPressed:(id)sender {
TWWebViewController *webView = [[TWWebViewController alloc] init];
webView.website = [NSURL URLWithString:#"http://apple.com"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
//
// TWWebViewController *wbc = (TWWebViewController *)segue.destinationViewController;
//}
#end
TWWebViewController.h:
#import <UIKit/UIKit.h>
#interface TWWebViewController : UIViewController
{
UIWebView *webView;
NSString *website;
}
#property (strong, nonatomic) IBOutlet UIWebView *webView;
#property (strong, nonatomic) NSURL *website;
#end
TWWebViewController.m:
#import "TWWebViewController.h"
#import "TWWebViewController.h"
#interface TWWebViewController ()
#end
#implementation TWWebViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:self.website];
[self.webView loadRequest:urlRequest];
NSLog(#"%#", website);
// Do any additional setup after loading the view.
}
I'm fairly new to iOS Development, so I'm not quite sure if I'm even on the right track. Any help would be appreciated, thanks!
You need to push your controller after initializing it: Also, your NSString is not an NSURL object so do this also in your TWWebViewController: NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:self.website]];
TWWebViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:
[NSURL URLWithString:self.website]];
[self.webView loadRequest:urlRequest];
}
TWViewController.m:
- (IBAction)sportsPressed:(id)sender
{
TWWebViewController *webView = [self.storyboard
instantiateViewControllerWithIdentifier:#"WebView"];
webView.website = #"http://apple.com";
[self.navigationController pushViewController:webView animated:YES];
}
Also don't forget to do this in your storyboard file:
I want to initialize a UIWebview object inside of my WebViewController. I'm having a bit of trouble initializing it, and directing it to the URL that is sent to it from the previous ViewController.
In the viewDidLoad of my WebViewController, I attempt to initialize it with the following:
UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:theFrame];
NSURL *url = [NSURL URLWithString:_itemURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
self.myWebView = tempWebview;
[tempWebview loadRequest:urlRequest];
_myWebView.delegate=self;
[WebViewController loadRequest:urlRequest];
However, this gives me errors stating:
use of undeclared identifier'theFrame', and no known class method for selector loadRequest.
Full code is below:
WebViewController.h:
#import <UIKit/UIKit.h>
#import "MatchCenterViewController.h"
#interface WebViewController : UIViewController
#property (strong, nonatomic) NSURL *itemURL;
#property (weak, nonatomic) IBOutlet UIWebView *myWebView;
#end
WebViewController.m:
#import "WebViewController.h"
#interface WebViewController ()
#end
#implementation WebViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:theFrame];
NSURL *url = [NSURL URLWithString:_itemURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
self.myWebView = tempWebview;
[tempWebview loadRequest:urlRequest];
_myWebView.delegate=self;
[WebViewController loadRequest:urlRequest];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
First you need to define that you are going to use the UIWebView Delegate in your .h file as:
#interface WebViewController : UIViewController <UIWebViewDelegate>
When you already have a webView defined in your Xib file, why are you creating another UIWebView and assigning it to the IBOutlet's webView? You could simply do:
self.myWebView.delegate = self; //Note that I have set the delegate first before calling LoadRequest
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.myWebView setScalesPageToFit:YES];
[self.myWebView loadRequest:request];
I want to open links of uiwebview in to the safari browser my code is working perfectly if I implement shouldStartLoadWithRequest method in viewController but when I implement shouldStartLoadWithRequest in same class and set UIWebView's delegate to self it doesn't work it get halt in between and shows assembly level code with error EXC_BAD_ACCESS(code=2, address=0x9) my files are as follows
//content of ShowView.h file
#import <UIKit/UIKit.h>
#interface ShowView : UIView <UIWebViewDelegate> {
}
- (void) showViewFunction;
#property (nonatomic, assign) UIViewController *mainViewContObj;
#end
//content of ShowView.m file is :
#import "ShowView.h"
#implementation ShowView
- (void) showViewFunction {
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 150)];
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[aWebView setDelegate:self];
NSString *urlAddress = #"http://localhost/test/index.php";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
aWebView.delegate = self;
[aWebView loadRequest:requestObj];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[[[self mainViewContObj] view] addSubview:aWebView];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"In shouldStartLoadWithRequest method");
if ([[[request URL] absoluteString] isEqual:#"http://localhost/test/index.php"])
return YES;
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
#end
// Content of ViewController.h
#import "ViewController.h"
#import "ShowView.h"
#interface mnetViewController ()
#end
#implementation mnetViewController
- (void)viewDidLoad {
[super viewDidLoad];
MNETMobAd *bannerObj = [[MNETMobAd alloc] init];
bannerObj.mainViewContObj = self;
[bannerObj showAd];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Some times html page shows but when I click on link it opens in same UIWebview window, and not even going into the shouldStartLoadWithRequest method, am I doing anything wrong?
Your code isn't clear, might need more info's, but from what i see, the ShowView class is never instanciated, so it shouldn't even show.
you should make something like this i guess :
//mnetViewController.m
#import "mnetViewController.h"
#import "ShowView.h"
#interface mnetViewController ()
#end
#implementation mnetViewController
- (void)viewDidLoad {
[super viewDidLoad];
ShowView* theShowView = [[ShowView alloc] initWithFrame:CGRectMake(insert the frame you want your webview to have)];
theShowView.autoresizesSubviews = YES;
[self.view addSubview:theShowView];
[theShowView release];
MNETMobAd *bannerObj = [[MNETMobAd alloc] init];
bannerObj.mainViewContObj = self;
[bannerObj showAd];
}
now for the ShowView class, try something like this :
//ShowView.h
#import <UIKit/UIKit.h>
#interface ShowView : UIView <UIWebViewDelegate> {
}
#end
//ShowView.m
#import "ShowView.h"
#implementation ShowView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
aWebView.scalesPageToFit = YES;
[aWebView setDelegate:self];
[self addSubview:aWebView];
NSString *urlAddress = #"http://localhost/test/index.php";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
[aWebView release];
}
return self;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"In shouldStartLoadWithRequest method for URL : %#",[request [URL absolutString]]);
if ([[[request URL] absoluteString] isEqual:#"http://localhost/test/index.php"])
return YES;
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
This should work, i didn't try it, i'll comeback tomorrow to try it if necessary.
I recently started an Xcode project, and its mostly web-based, in the sense it mostly works with UIWebView. I am a total noob at this. I would like to make an "No Internet Connection Alert". Basically An Alert that comes up if you have no internet connection. I have tried using the Reachability but since I'm such a noob, I didn't manage to figure ANYTHING out.. Heres my view controller:
This is my .h file: P.S: My WebView is called 'webone'.
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
-(IBAction)refreshClicks:(id)sender;
#property (weak, nonatomic) IBOutlet UIWebView *webone;
#end
And This is My .m file:
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webone;
-(void)viewDidLoad {
NSURL *url = [NSURL URLWithString:#"http://www.lostcraft.net/mobile"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webone loadRequest:req];
[super viewDidLoad];
}
-(void)awakeFromNib{ //IGNORE
[self refreshClicks:self]; //IGNORE
}
-(IBAction)refreshClicks:(id)sender{//IGNORE
[webone loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.lostcraft.net/mobile"]]];//IGNORE
}
- (void)viewDidUnload
{
[self setWebone:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
Place this in your .m file
Under Your IBAction:
NSString *web = #"http://YOUR WEB ADRESS HERE";
NSURL *url = [NSURL URLWithString:web];
NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
[webdone loadRequest:requestUrl];
Then somewhere in your .m
-(void)webView:(UIWebView *)webdone didFailLoadWithError:(NSError *)error {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please check your internet connection" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
go into connections tab in interface builder in xcode
Right click from the delegate as shown in the picture (the top option) and drag it to your view contoller where you have your web view (webdone)