webview not working in objective c - ios

I am trying to load a series of urls based on the contents of my database i.e: http://www.whatever.com but when I run the app in the simulator nothing appears, my code reads as follows
.h file (imports statements excluded)
#interface FSFourthScreenViewController : UIViewController
//insert code to create web view
{
NSString * urlString;
UIWebView * FSWebView;
}
// properties
#property (nonatomic, retain) NSString * urlString;
#property (nonatomic, retain) IBOutlet UIWebView * FSWebView;
#end
.m file import statements excluded
#interface FSFourthScreenViewController ()
#end
#implementation FSFourthScreenViewController
#synthesize FSWebView, urlString;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//background image
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"backgroundimage.png"]];
NSURL * url = [NSURL URLWithString:urlString];
NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];
[FSWebView loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have wired the webview correctly, and assigned the right field in the database. I also cleaned out xCode and the simulator, but still no joy... any ideas welcome?

add this code ,check your objects:
- (void)viewDidLoad
{
[super viewDidLoad];
//background image
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"backgroundimage.png"]];
NSURL * url = [NSURL URLWithString:urlString];
if (!url)
{
NSLog(#"url is nil!!!");
}
NSURLRequest * requestObj = [NSURLRequest requestWithURL:url];
if (!FSWebView)
{
NSLog(#"RSWebView is nil!!!");
}
[FSWebView loadRequest:requestObj];
}
i guess the url is nil ,or the webview is nil

Try it,
[self.FSWebView loadRequest:requestObj];

Set the urlString. In the code you provided, the urlString is never set, so the URL you create with it cannot be loaded.

You can follow this tutorial :
http://mrudulajampala.blogspot.ca/2012/10/uiwebview-tutorial.html
And you find its source code here:
https://sites.google.com/site/iphonesdktutorials/sourcecode/UIWebViewTutorialPart1.zip?attredirects=0
Hopefully it will help you out.

If your project is iOS6 and abrove you can use this tool the web inspector to be sure that the web page is loading without any error.
You can follow this tutorial :
http://moduscreate.com/enable-remote-web-inspector-in-ios-6/
i hope it will help you to find the problem

Your code is correct. But your urlString is null . That is why it is not showing anything.
you just add an an url , and then test for it

As I see you havent UIWebViewDelegate in your FSFourthScreenViewController.h. You need to add it and to add its delegate WebView methods to your FSFourthScreenViewController.m
Check documentation for more details of UIWebViewDelegate :
Documentation

Add
<UIWebViewDelegate> in your view controller
self.FSWebView.delegate=self;
NSURL* url = [NSURL URLWithString:#"http://i.wrightscs.com"]; //replace your string here
[self.FSWebView loadRequest:[NSURLRequest requestWithURL:url]];
Hope it helps you...

Related

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 !

ios UIButton not loading url in UIWwebview

I have made an iOS app to load a simple UIWebView *mWeb.
Once the app starts it loads my originalURL.
At the bottom of the UI, I have a UIButton placed *btnHome.
When I click this UIButton I want it load another URL *loadNextURL.
However something's not working on my end... HELP!
Here's the code for my myViewController.h file.
#import "myViewController.h"
#interface myViewController ()
#property (weak, nonatomic) IBOutlet UIButton *btnHome;
#property (weak, nonatomic) IBOutlet UIWebView *mWeb;
#end
#implementation myViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *originalURL = #"http://myOriginalLink";
NSURL *url = [NSURL URLWithString:originalURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_mWeb loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)btnHome:(id)sender
{
NSString *loadNextURL = #"http://link2";
NSURL *url2 = [NSURL URLWithString:loadNextURL];
NSURLRequest *reqObj = [NSURLRequest requestWithURL:url2];
[_mWeb loadRequest:reqObj];
}
#end
Well there can be two problems, first check that your action method is bound to the button or not. Second the url in stringVariable loadNextUrl is valid or not.
Now how to check the url is valid or not, just copy the url and paste into the browser. If the link does not open then the url is not valid. So for that pass the valid url in the string variable and then try.
Check your Url it may be invalid. If it works fine in your browser then check your method. It may not be linked with your button with touchUpInside event. Then try using [yourWebView loadRequest:[NSURLRequest requestWithURL:#"yourLink"]]; . Also do check whether your web view is not nil. It won't be nil as you are able to load it in viewDidLoad. But do check it.

iOS UIWebView does not show the websites correct

I am creating a simple UIWebView like shown.
All works fine but the websites are corrupted. it looks like, the images arent loaded.
Curious is, that in the Browser, the same page is loading fine O_o Any Ideas?
#import "WebViewController.h"
#interface WebViewController ()
#property NSURL *adUrl;
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
#implementation WebViewController
-(id) initWithUrl:(NSURL *)url
{
self = [super init];
if (self)
{
self.adUrl = [NSURL new];
self.adUrl = url;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.webView loadRequest:[NSURLRequest requestWithURL:self.adUrl]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Task solved. The Problem was, that an old Class which was responsible for WebCaching was disturbing the redirect and on that way it suppressed the load of baseURL objects. Thanks for givin me ideas how to solve.
Cheers

Showing images in ios webView not working

Im having some problems with showing an imagelink on ios webbView. What's happening is that I've put down a webView in my xib file and connected it with outlet but i stil can't get the image to show up..
The code in ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
NSString *urlLink = #"http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=90645/sv-se&type=1&id={FDCE3A18-B5F6-45F4-B9B2-EA9171290F71}&period=&week=41&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=844&height=629&maxwidth=844&maxheight=629";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlLink];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[self.webView loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
If someone could figure out what the problem is i'd be grateful!
Best regards Oliver
http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=90645/sv-se&type=1&id={FDCE3A18-B5F6-45F4-B9B2-EA9171290F71}&period=&week=41&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=844&height=629&maxwidth=844&maxheight=629
This is not a direct link to an image. That's probably your issue. Try using a normal image link like this https://www.google.com/images/srpr/logo3w.png and it should show up.

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