UIWebView in tabbed application (Xcode) - ios

I'm just starting to learn Xcode, and have run in to some problems...
I've made a tabbed application in Xcode 4.3 which works as deired. But I previously made a simple UIWebView application, that I would now like to implement into one of the tabs on the new application.
This is what I've done in the classes for FirstViewController:
// FirstViewController.h
// SafeLine
//
// Created by Camilla Fröberg on 2012-03-27.
// Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController {
IBOutlet UIWebView *webDisplay;
}
#property(nonatomic,retain) UIWebView *webDisplay;
#end
And the FirstViewController.m:
// FirstViewController.m
// SafeLine
//
// Created by Camilla Fröberg on 2012-03-27.
// Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webDisplay;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webDisplay loadRequest:requestObj];
[super viewDidLoad];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#end
When running the application I won't get any error message, and it will not show the website, instead it will only show an empty view...
Any help is appreciated!
// Best regards
Camilla from Sweden

I think, you should check if you connected the UIWebView in the Interface Builder with IBOutlet.

Related

I can't leave pdf with webview

Does anyone know how to leave pdf with webview
this app is done with xcode,i learn it from internet
but I got a issue, when I click a download link
it would open the file in app , but I can't go back to
previous page , I can't do anything but close app & restart
So what should I add to make app go back to previous page
here is my app ,
viewcontroller.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webview;
#end
viewcontroller.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *url = [NSURL URLWithString:#"http://mywebsite/index.php"];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

UIWebView Screen Fitting Issue

I have developed a website in Twitter Bootstrap, I am now using a UIWebView to display that site inside of an IOS app. I am getting it to display fine, but the screen is off and it is running off of the side of the screen... I feel like I might have my UIWebView configured wrong, the site looks like if I go to it in Safari on my mobile device, so I know the site is working properly.
It even displays Google wrong in the UIWebView.... I will display my code and 2 screen shots below(The first screenshot is what it currently looks like, the second is what it should look like and what it looks like in safari mobile :
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIWebView *webView;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
_webView.scalesPageToFit = YES;
_webView.frame=self.view.bounds;
[_webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
AS-IS Screen Shot
TO-BE Screen Shot
No need to use loadRequest: two time, Use:
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[_webView reload];
}
To me it looks like the UIWebView is not set up correctly in the Storyboard or Interface Builder. Do you use Auto Layout? If so, are the constraints set correctly?
A simple way to make sure the UIWebView is displayed full screen would be to add 4 constraints that align it with the top, bottom, leading and trailing edges of its superview, e.g. like so:
EDIT: Here are some rough instructions on how to add those constraints.
You should add the following code after [_webView loadRequest:request]; :
_webView.scalesPageToFit = YES;
and If your UIWebView is not located properly, add the following code too :
_webView.frame=self.view.bounds;
In the Utilities pane, select "Scales Pages to Fit":
In the view controller in which the web view resides, make sure you can view the boxes (or bounds) of the view (note: the bottom doesn't appear because I couldn't fit it within the image):
Code in view controller:
#import "SomeViewController.h"
#interface SomeViewController ()
#end
#implementation SomeViewController
#synthesize webView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *urlLink = #"www.google.com";
NSURL *url = [NSURL URLWithString:urlLink];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:urlRequest];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Photo of the other settings in the view controller:

Open an URL in UIWebView

I have an important question. I'm creating an iPhone app.
I have an UIWebView (https://www.google.de/) with goBack, goForward and reload.
Now, I want a Button e.g. Bar Button Item named Home or Homepage, to open an URL (https://www.google.de/) in this WebView, to go back to the homepage.
How can I do this? How can I "say" the button to open the link in my WebView? I ask for answer.
// ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIWebView *site ;
#end
// ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)refresh:(id)sender; {
NSURL *url=[NSURL URLWithString: #"https://www.google.de/"]; NSURLRequest * requestURL=[NSURLRequest requestWithURL:url]; [_site loadRequest:requestURL];
}
- (void)viewDidLoad {
[self refresh:self];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
UIWebView has methods, goBack and goForward. You can make actions and bind it with your bar buttons to go back and forward whenever you want.
- (IBAction)goBack:(id)sender {
[_site goBack];
}
- (IBAction)goForward:(id)sender {
[_site goForward];
}
- (IBAction)goHomepage:(id)sender {
NSURL *url=[NSURL URLWithString: #"https://www.google.de/"];
NSURLRequest *requestURL=[NSURLRequest requestWithURL:url];
[_site loadRequest:requestURL];
}
To help you more, here's a tutorial on this, and if you don't want to read that tutorial, you can check their source code from here !

UIWebView not appearing - Xcode 6

my project won't show the web view no matter what code i try use. I even tried a youtube tutorial. I know this question has been asked many times but it doesn't make sense to me. I used this tutorial https://www.youtube.com/watch?v=AmMF7hWrYZk
Heres my code
If you need more detail please ask me. I'm knew to objective c
ViewController.m
// FirstViewController.m
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
ViewController.h
//
// FirstViewController.h
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIWebView *webView;
#end

UIWebView show blank to iOS dev beginner

I'm new for iOS develop. I tried to make a very simple app just show a UIWebView which display a web page:
ViewController.m:
#import "ViewController.h"
#implementation ViewController
#synthesize webView = _webView;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *urlAddress = #"http://jsfiddle.net/emj365/qaQnF/embedded/result/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
}
...
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
UIWebView * _webView;
}
#property (nonatomic, retain) IBOutlet UIWebView * webView;
#end
UIWebView show blank. What's wrong?
There are a few different things that could go wrong. A few options you should check:
Did you check to see if the outlet was actually connected to the webview in the xib?
Implement the UIWebView delegate and check for (networking) errors

Resources