First thanks in advance to have a look on my issue. My issue is my am developing webview based application. It's same like as browser but i have a issue related to reload web view. When i am getting a value form popover bookmarked and try to reload the current web view from this next bookmark url, my web view do noting. I am stuck in this issue. Although when i enter any url through it works perfectly. May i doing something wrong with web view ?
temp = appDeleg.strURLFromPopover;
NSURL *url = [NSURL URLWithString:temp];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.myWebView loadRequest:requestObj];
[self.myWebView setDelegate:self];
[self.view addSubview:myWebView];
Please have a look..
The last line looks like very suspicious. In my experience, [self.view addSubview:myWebView] should be placed in the "initialization block" to avoid some lazy init issues. Are you sure All objects are NOT nil? if so, you can try to set UIWebView's delegate to your class, and debug in each method to test if your object are properly initialized. I tried your code, work fine in my side. Below are delegate method you might consider about
– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webViewDidFinishLoad:
– webView:didFailLoadWithError:
Related
I need to display webpage using URL. From that page I want to remove one link control from that html page. Is it possible? I am opening it with this kind of code.
NSString *urlAddress = #"http://myurl.com";
NSURL *url = [NSURL URLWithString:urlAddress];
If you want to disable ALL links, see the answer from user3182143...
If you only want to disable a specific link, you can still use those methods - you will just need to evaluate the request part of shouldStartLoadWithRequest:(NSURLRequest *)request and decide whether to return YES or NO
If you want a specific link to look different, you'll need to modify the html. Couple ways to do so, but we really need more information about exactly what you are trying to do.
Are you displaying ONE specific web page? And all you need to do is change ONE link in that ONE page, and you're done? Are you displaying a series of pages? Do you have any control of the pages? And so on.
I'd suggest you start searching for and reading about uiwebview insert html or uiwebview insert javascript
We can do this.
First we should know about the UIWebViewDelegate methods
First create BOOL
ViewController.h
#property (nonatomic) BOOL ret;
ViewController.m
#synthesize ret;
Set BOOL to NO in below delagte method
- (void)webViewDidFinishLoad:(UIWebView*)webView {
// Sent after a web view finishes loading a frame.
ret = NO;
}
Then If we return NO in below delegate method, this will prevent the user from viewing link
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
return ret:
}
Dave DeLong's Disable Link in UIWebView answer
Removing hyper links from a URL shown in UIWebView
Actually I have two related questions here, about different use cases of loading requests in a UIWebView.
Is it safe to call - [UIWebView loadRequest:] on a web view that is inserted in the view hierarchy and its hidden property or the one of its superview is set to YES?
Is it safe to call - [UIWebView loadRequest:] on a web view that is not inserted in the view hierarchy?
In particular I'm interested whether it is considered to be a good practice to load request in a UIWebView that is not visible, and whether the delegate assigned to the instance of UIWebView will be notified once the request succeeds/fails. The reason I'm asking is that UIWebView class reference says "create a UIWebView object, attach it to a window, and send it a request to load web content", where the part telling that a UIWebView should be attached to a window makes me doubt if the above approaches are reliable.
I have successfully used [UIWebView loadRequest:] with objects that are not in the view hierarchy. I expect that the class reference just assumes that the view will be displayed as it's probably the most common use case.
Yes it is safe to call [UIWebView loadRequest:] on a web view that is inserted in the view hierarchy.Because you are going to use web in the view.Also if you just give the URL in the program,it is enough to get.
The following code for [UIWebView loadRequest] is
NSString *strurl =#"http:www.google.com";
NSURL *url=[NSURL urlWithString:strurl];
NSURLRequest *urlrequest =[NSURLRequest requestWithUrl:url];
[webView loadRequest:urlrequest];
Even it is safe to call [UIWebView loadRequest:] on a web view that is not inserted in the view hierarchy.Because you can dynamically create the view and write the code for web view through the program.
It works. The approach is completely reliable as long as you are not using any private API and following HIG. It is not a bad practice as long it suits to your requirement. If there is a hidden property available to you for UIWebView then of-course you can hide the webView as per your requirements.
About your below query, it is written in the documentation as per the sentence context.
The reason I'm asking is that UIWebView class reference says "create a
UIWebView object, attach it to a window, and send it a request to load
web content", where the part telling that a UIWebView should be
attached to a window makes me doubt if the above approaches are
reliable.
The full context is below, which clearly means that to display a webpage in your application using UIWebView, you have to do it in the mentioned way.
You use the UIWebView class to embed web content in your application.
To do so, you simply create a UIWebView object, attach it to a window,
and send it a request to load web content.
I am going to try to explain my issue the better I can.
So I have a UINavigationController. Inside I have a UITableView using JSON to get a list of arrays. When the user presses on a cell, it takes them to the detail view, where there I have a new view with information and UITableView that displays a new array from JSON. Each view has its own URL with different data. Now, the issue that the app crashes when I push on the detail view. It loads at first but then it crashes. If I remove the code to display the tableview and all the JSON stuff, it works just fine. The code is well written as far as I know. I created a whole new page using the same code of the first view where is the main tableview, and it still crashes. I have no idea why. From top of my head, it looks like the app doesn't allow me to use a new tableView with its data from the web using JSON but it does allow me to use it on my main view.
Ok, now, here are the codes I'm getting when it crashes (The codes are not always the same):
This the line where is crashing at:
cell.textLabel.text = [[news objectAtIndex:indexPath.row]objectForKey:#"Series"];
I get all these crashes each time I build the app over and over again:
1: THREAD : EXC_BAD_ACCESS (code=1, address=0x5000000c)
2: THREAD : EXC_BAD_ACCESS (code=1, address=0xc)
3: THREAD : EXC_BAD_ACCESS (code=1, address=0x41c8000c)
4: Thread 1: signal SIGABRT
And the console log:
and this one too:
And the codes keep coming on and on.
This is the code I use to call the URL:
NSString *urlString = [NSString stringWithFormat:#"http//MYURL.com/%#blahblah%d",fullDate, [[NSTimeZone localTimeZone] secondsFromGMT] / -60];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[[NSURLConnection alloc]initWithRequest:request delegate:self];
Any ideas? Thank you!
Your news object is being deallocated prematurely. Check to make sure your keeping a strong reference to it (strong for arc, otherwise use retain). The memory that used to store your news is clearly being used by some CALayer now, and since CALayer does not respond to objectAtIndex:, your program is crashing. Use Zombies to find when your news object is actually being deallocated.
I am currently embedding a UIWebView inside a UICollectionViewCell to be able to view HTML formatted text residing in my local data structure.
I know it has been stated many times one should not embed an UIWebView inside a scrollView, but i currently see no other way to achieve displaying mixed content overviews (That is the current requirement, and so far UICollectionView does work very well with large data sets).
The Problem is, that i am not able to call the UIWebViews Delegate method:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType { ... }
I need the delegate method to be able to display external links or call local methods.
Is there a way to achieve this? Maybe by handing over the events programatically?
Thanks for the feedback!
I just found out what i did wrong:
I just needed to update the cells' contentView: [[cell contentView] setFrame:frameContainingWebViewSize]
That did the trick. The delegate method was not called because the contentView did not cover the webview (clipSubviews is set to NO) and thus the tap events where not fired.
I'm having this problem in my iPhone app: I have a webView which is first loaded with an HTML string. After the user clicks a link and it loads the requested page, the webView won't go back when I call the method [UIWebView goBack]; I suppose webView doesn't cache the HTML string. Is there any way I can make webView cache my HTML string without having to save it in a NSString myself?
You can use the canGoBack property and if you can't go back, reload the UIWebView with the original html. If the user has navigated forward using links then the canGoBack property will return YES and a goBack can be initiated on the UIWebView. The _htmlString is a member variable that is set when the UIWebView is initialized using an HTML string. -rrh
- (void)goBack
{
if (_htmlString && ![_browserWebView canGoBack]) {
[_browserWebView loadHTMLString:_htmlString baseURL:nil];
return;
}
[_browserWebView goBack];
}
Try to create a NSURLRequest from the file URL and use loadRequest instead of loadhtmlString
NSURL *htmlFileUrl = [[NSBundle mainBundle] URLForResource:#"index" withExtension:#"html"];
NSURLRequest *localRequest = [NSURLRequest requestWithURL:htmlFileUrl];
self.webView.delegate = self;
[self.webView loadRequest:localRequest];
This sounds like a your webview variable isn't properly linked up to the webview instance that you are using. Breakpoint at this call and check whether your webView variable is 'nil'.
If it is, make sure your webView in your XIB file is linked to an IBOutlet variable in Interface Builder. This is a common mistake and something I tend to forget when designing a new page for the first time.
This tutorial covers a LOT on how to build interfaces using Interface builder which i'm sure you're familliar with but for those that aren't it's also useful. It has some good screenshots which help illustrate what I mean by 'linking' better than me typing "click the little + icon and drag the little thingy on to the UI element" :)
http://www.icodeblog.com/2008/07/30/iphone-programming-tutorial-connecting-code-to-an-interface-builder-view/
EDIT
The only other thing i can think of is that you are overwriting your webView variable by re-initialising it somewhere (it is already initialised by the XIB) and therefore you're calling goBack on a webview that doesn't exist on the screen.