Some help please,
I am putting a web app together and I am stuck on a few things.
I have tabviewcontrollers which load different uiwebviews.
Each time I navigate on the app and re-click the tab it remains where I was on that page is there a way to re-load it so it always goes from the orginal ur (not just a refresh)?
Any advice on the best way to handle this would be appreciated.
Thank you
Steve
Load the request in your view controller's viewWillAppear: method.
When you want to refresh, use
[webView reload]
or for if you want t reload with a specific url
NSURL *theURL = [NSURL URLWithString:#"http://urltoreload.html"];
[webView loadRequest:[NSURLRequest requestWithURL:theURL]];
Related
I need to clean the content of UIWebView(in order to reuse it), but I have some authentication handling code in its delegate methods, so I do not want to load an empty page like about:blank to clean it, as it will trigger my authentication handling code. So is there a way for doing this?
(also, by reusing it, I need to put a spinner on top of the web view, and when it loads another page, I don't want the user see the previous loaded page content, so that's why I need to clean it)
Thanks!
You can just use this line of code :
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]]];
Here you will find whole demo
this did the trick for me:
[webView stringByEvaluatingJavaScriptFromString:#"document.open();document.close()"];
Try this out. This worked for me
[self.webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML = \"\";"];
If your only problem is that the spinner disappears when you load a blank page, you can use this code in webViewDidFinishLoad:
– (void)webViewDidFinishLoad:(UIWebView *)currentWebView {
if (![currentWebView.request.URL.description isEqualToString: #"about:blank"]) {
self.mySpinner.hidden = YES;
}
}
...then the spinner will go on until your webview is actually done loading.
I'm making an iPhone app using xcode, but whenever the homepage (localHTML) is visited using the backbutton, the list item stays highlighted. My solution to this is to refresh the page whenever the localHTML is visited. Can anyone suggest an easy way of detecting when the url matches localHTML (should I use isFileURL?) Thanks for your help. Also, the list was made with javascript or else I would use deselectRowAtIndexPath.
This is what I came up with, but it doesn't work
-(IBAction)backbutton{
[webView goBack];
NSString *currentURL = webView.request.URL.absoluteString;
if (currentURL = "whatever the file path is") {
[webView reload];
}
is this a valid way to accomplish this? is there a way to get my localhtml's file path by using nslog?
Have you tried having a delay after going back, then refreshing?
eg. after
[webView goBack];
have a delay now using nstimer
then
[webView reload];
I am doing this in my app :
-
(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.i
NSURL *url = [NSURL URLWithString:#"http://www.mySite.fr"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.myWebView loadRequest:request];
self.myWebView.scalesPageToFit = YES;
}
When i have not the network ( no connexion) nothing is shown ( just a white page witch is the web view).
My question is should i put an alert to the user when there is no network ? how i ca do this ? thanks ? will my app rejected if i don't show an alert to the user ?
Thanks for your answers
While it makes sense to check for reachability, I think you have a better approach using the delegate method webView:didFailLoadWithError: which will tell you if the web view has failed to load your page. In such a case, rather than popping an alert view load some kind of local HTML page indicating that the load has failed if you wish and set a timer to trigger a reload after a while.
As such I don't think Apple will reject you for this unless it is the only thing the App does. But you will have to give a thought on the user experience when the load fails.
I do not think that not checking for a connection will cause your app to be rejected, but you should do it anyway.
Ed Marty has pointed out that my original suggestion of using
- (BOOL)checkResourceIsReachableAndReturnError:(NSError **)error
will not work in iOS (thanks!).
This StackOverflow question appears to have a working solution to the problem.
1) user launch application
2) user press button
3) button loads http://domain.com/mypage/?item=123
How do you trigger http://domain.com/?item=123, without opening the actual page in the browser?
NSURLConnection is the answer.
Not 100% sure of what the question is, but you could use a UIWebView. Load that UIWebView in the app with the URL and you should be good to go.
Hope this helps!
NSString* str = [NSString stringWithContentsOfURL:[NSURL URLWithString:#"http://domain.com/?item=123"] usedEncoding:NULL error:NULL]
I have used a UIWebView set to "hidden". It probably is not the most efficient way but if you normally use UIWebViews and Interface Builder then it is easy. You can also use the webview delegate methods to watch it.
On second thought - use the NSURL String method above but put it in a new thread.
hi i guess this is pretty simple and hope it will be answered in a easy manner!
how do i change the url of the uiwebview when a button is touched up inside?
meaning to say i will have a single web view and everytime a button is clicked the URL of the webview
changes and a new page is reloaded
thanks
As you suggest, it's very easy:
-(void)buttonPressed:(id)sender {
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://website.com/"]]];
}
This is all very well documented.