Make a UIWebView Public - iphone

I have a UIWebView object declared in my view controller and I want to make it load a different page when the app recieves a notification while the app is running using application:didRecieveRemoteNotification:. I'm having trouble accessing the object from inside the appDelegate.
Any simple way to do this?
this is how I declare my web view
.h
IBOutlet UIWebView *webView;
#property (nonatomic, retain) UIWebView *webView;
.m
#synthisize webView;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:currentPath]]];

this is not the best idea to show the web view from outside the controller. Just add method like this to controller:
-(void) loadFromPath:(NSString*) path {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath: path]]];
}
and call it in your app delegate when you need.

Related

Opening another view from a UITableViewCell

I am attempting to open links embedded in a custom table view cell using a UIWebView in the same scene. However, I when I tap the button the webview doesn't open in response. The button is working (it will print an NSLog), and the webview will show if I set it visible in ViewDidLoad in the "HouseItemsViewController."
The Table View contains my custom cells, and I am trying to show the highlighted View:
Imgur image of my "House Items View Controller" Scene
The HouseItemsViewController contains a method to accept a NSURL:
- (void)displayWebViewWithURL:(NSURL *)targetURL
{
NSURL *url = targetURL;
NSURLRequest *myrequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:myrequest];
theURLView.hidden=NO;
}
The custom table view cell includes an action:
- (IBAction)congressUrlLink:(id)sender
{
HouseItemsViewController* billViewController = (HouseItemsViewController*)self.tapHandler;
[billViewController displayWebViewWithURL:congressUrl];
}
Where tapHandler is defined:
#property (nonatomic, copy) void (^tapHandler)(id sender);
What's the right way to reference the HouseItemsViewController from here and to execute the displayWebViewWithURL:(NSURL *)targetURL method?[
I would assign the tapHandler manually as a delegate.
#property (nonatomic, weak) HouseItemsViewController *delegate;
synthesize it, and assign it manually after initializing your table view cell:
[myCell setDelegate:self];
Hope this helps

Passing variables to the view from AppDelegate

i open a view in AppDelegate
with:
AppDelegate
PushDetail *pushdtls = [[PushDetail alloc] initWithNibName:nil bundle:nil];
pushdtls.seminarurl = [NSURL URLWithString:resourcePathURL]; /passing URL
[self.window presentModalViewController:pushdtls animated:YES];
PushDetail.h
#property (nonatomic) NSURL *seminarurl;
PushDetail.m
- (void)viewDidLoad
{
NSURLRequest *requestObj = [NSURLRequest requestWithURL:seminarurl];
[pushDetails loadRequest:requestObj];
}
But the webview is empty... what I do wrong?
and the second question how to close the view I opened?
- (IBAction) closeNews{
//[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
//[self release];
[self dismissModalViewControllerAnimated:YES];
}
does not work :(
You may implement the UIWebViewDelegate protocol within your view controller and fetch the results/error messages yourself.
Namely didFailLoadWithError - see the UIWebViewDelegate Protocol References for more.
Maybe its just a typo on your URL.
Example:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(#"oops, failed with error: %#", error);
}
You've not specified what pushDetails is, but I'm assuming it's an IBOutlet to a UIWebview on your PushDetail controller. My guess is that you've forgotten to bind your pushDetails outlet to the webview in your nib file.
You could create lets say a file that holds all your global variables lets call it GlobalVariables.h and .m. In the GlobalVariables.h file add this
extern NSURL *seminarurl;
#interface GlobalVariables
#property (retain, nonatomic) NSURL *seminarurl;
#end
and in the GlobalVariables.m file add
#import "GlobalVariables.h"
#implements GlobalVariables
#synthesize seminarurl;
NSURL *seminarurl; // You could add what your URL is here as well you would just use '='
#end
So when you want to access it or assign a variable to it, it would just be like accessing or assigning any other variable. Just remember to import 'GlobalVariables.h' into which ever .m file you are using it in.
make your property retained. ex >> #property (nonatomic,retain).
if the url is a property in your app delegate .. you can access it like this
[UIApplication SharedApplication].delegate.yourpropertyname;

iPhone - webViewDidFinishLoad not called

I have a simple View into IB that contains just a UIWebView and a UIButton.
The webView is retained, connected, not nil, the delegate property os also connected, the Controller is UIWebViewDelegate compliant and set in the .h.
in ViewDidLoad, I use [self.webView loadHTMLString:htmlContent baseURL:nil];
The content loads, but webViewDidFinishLoad is never triggered, neither didFailLoadWithError, neither webViewDidStartLoad.
How can I know when my content has finished loading, as it take a short time, but still a time to load (and I need to do things during that time on display, for an example not showing the button) ?
#interface MyController : UIViewController <UIWebViewDelegate> {
UIWebView* webView;
}
#property (nonatomic, retain) IBOutlet UIWebView* webView;
#end
#implementation MyController
#synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
constructing the htmlString
id a = self.webView.delegate; // for debug
[self.webView loadHTMLString:htmlContent baseURL:nil];
}
#end
EDIT :
I've deleted the whole XIB and built it from scrathc : no more problem. IB sucks sometimes.
You need to implement the UIWebViewDelegate protocol in your class and set the delegate property of self.webView = self. You will need to implement non-optional delegate methods to the class, plus the webViewDidFinishLoad, didFailLoadWithError and webViewDidStartLoad methods.
I've deleted the whole XIB and built it again from scratch : no more problem. IB sucks sometimes.
Just a sort of stab in the dark. As far as your code above is concerned, you still haven't set the responding object to the webView delegate, you have set a pointer to the webView delegate object but when the webView goes to respond to the delegate it will still be nil.
You should probably have: self.webView.delegate = a; but even then I don't know if that will work because I don't know what a is, is it the object that will respond to the delegate call backs?
You have to implement the UIWebViewDelegate protocol in your class and set self.webView.delegate=self;

How to hide buttons in iOS when webview has finished loading

I am not sure why is this set of codes not working to hide iphone buttons as soon as the webview has loaded?
GoogleMap_BetaViewController.h
#interface GoogleMap_BetaViewController : UIViewController <UIWebViewDelegate> {
IBOutlet UIWebView *webView;
UIButton *retrieveReminder;
}
#property (nonatomic, retain) UIWebView *webView;
#property (nonatomic, retain) IBOutlet UIButton *retrieveReminder;
- (IBAction) RetrieveReminder:(id)sender;
#end
testController.m
#implementation GoogleMap_BetaViewController
#synthesize webView,retrieveReminder;
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[retrieveReminder setHidden:YES];
}
Jonathan, have you connect UIWebViewDelegate properly ? Have you check that WebViwDidFinishLoad get called everytime.
As commented in response above, make sure that you are going from Files Owner to the Button and not the Button to Files Owner (which will show you IBActions). Also, once you get the right variable hooked up, make sure you are using self.retrieveReminder so that you are accessing the variable through the getters/setters which is what the IBOutlet is hooked up to.
Based on our discussion in the comments, I guess you are linking it wrongly. Take a look at this video for a visual tutorial on linking IBOutlets. http://www.youtube.com/watch?v=-EpTGOcC0Jw
You need to set the webFiview delegate to self and then use its delegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
button.hidden = YES;
}
Have you tried to set the delegate of the webview in the IB? That is a must, as you are using its delegate method.

UIWebview does not show up into UINavigationController

I have a tabBar application. In the first tab, I have a navigation bar. In this navigation bar I have a table view. When the user clicks a cell of the table, it goes to another table view, and when the user clicks a cell in that table, it goes to a webview to open a web page.
Basically, it goes fine until opening the webview. In the webview, viewDidLoad is called and seems to work properly. However, webViewDidStartLoad is never called and the web page never shows up.
I am not using IB. I build the UITabBarController in the AppDelegate, where I also assign an instance of my UINavigationController for each tab.
I call the webview from the second UITableViewController as follows:
rssWebViewController = [[webViews objectAtIndex: indexPath.row] objectForKey:#"controller"];
[[self navigationController] pushViewController:rssWebViewController animated:YES];
I have checked that the navigationController is there and it seems just fine.
The viewDidload of my webview is as follows:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlAddress = self.storyUrl;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[self rssWebView] setDelegate: self];
[[self view] addSubview:[self rssWebView]];
[rssWebView loadRequest:requestObj];
self.rssWebView.scalesPageToFit = YES;
self.rssWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
}
The web view controller interface is defined as follows:
#interface RSSWebViewController : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *rssWebView;
IBOutlet NSString *storyUrl;
IBOutlet NSString *feedName;
}
#property (nonatomic, retain) IBOutlet UIWebView *rssWebView;
#property (nonatomic, retain) IBOutlet NSString *storyUrl;
#property (nonatomic, retain) IBOutlet NSString *feedName;
#end
Any help is greatly appreciated.
ok, I found out, I had to initiate my webview with a frame in viewDidLoad:
rssWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];