I have a UIWebView that uses a ATM HUD while the web page is loading. I can get the HUD to start working, but after the web page loads, it stays there. I need to find a way to get the HUD to stop spinning once loaded. Below is the code I have so far..
#implementation ThenewsViewController
#synthesize hud;
- (void)showHud {
// Show hud with activity indicator
NSLog(#"hud: %#", hud);
if (!hud) {
hud = [[ATMHud alloc] initWithDelegate:self];
[self.navigationController.view addSubview:hud.view];
[hud setCaption:#"Loading news..."];
[hud setActivity:YES];
[hud update];
if (![hud isBeingPresented])
[hud show];
} else {
NSLog(#"hud exists... resetting.");
hud = nil;
[self showHud];
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *myURL = [NSURL URLWithString:#"http://www.hiphopdx.com/m/index.php?s=news"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[myWebView loadRequest:myRequest];
UIColor *navBarColor = UIColorFromRGB(0x089932);
[[self.navigationController navigationBar] setTintColor:navBarColor];
if (![hud isBeingPresented])
[self showHud];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidFinishLoad:(UIWebView *)webView
{
NSLog(#"Done loading web view");
[hud hide];
}
#end
How about this?
ATMHud *blargh;
if(loaded)
{
blargh.hidden = YES;
}
Try this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// stop animating here
}
also
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// stop animating here also
}
Also make sure your "myWebView" instance delegate is set.
F.e _myWebView.delegate = self;
Related
I have two UIPopoverController. each one opens up a pdf in a UIWebViewDelegate when I click the respective buttons.
However,only one works.
Both buttons, A and B, have this format for the click function (except Button B would say ButtonB not ButtonA)
- (IBAction)openPDF_Pictures_A:(id)sender
{
ButtonAPDFViewController *DWV =[[ButtonAPDFViewController alloc] initWithNibName:nil bundle:nil];
self.masterPopOverController = [[UIPopoverController alloc] initWithContentViewController:DWV];
[self.masterPopOverController presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.masterPopOverController setPopoverContentSize:CGSizeMake(600, 800) animated:NO];
}
And in the UIViewController for each UIWebView, is this:
#import "ButtonAViewController.h"
#interface ButtonAViewController ()
#end
#implementation ButtonAViewController
#synthesize buttonAPDFView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"partA" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[buttonAPDFView loadRequest:request];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Both buttons A and B are on the same view. I did make one of the IBActions use masterPopOverController2 and one of the masterPopOverController to see if that would resolve anything but it doesn't. The one that doesn't work opens up a popover but it doesn't show the PDF in the popover. Any suggestions?
just realized I didn't add the UIWebView inside the UIView in the xib...
I have two View Controllers. In the first one i have a button and when you click it you need to display a Web Page in a second View Controller. When I click the button, I see only a black screen.
Here is TabulkaViewController.m code:
#import "TabulkaViewController.h"
#import "WebViewController.h"
#interface TabulkaViewController ()
#end
#implementation TabulkaViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_hbutton.layer.borderWidth = 1;
_hbutton.layer.borderColor = [[UIColor grayColor] CGColor];
}
- (IBAction)hbutton:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://apple.com"];
WebViewController *webViewController = [[WebViewController alloc] initWithURL:url andTitle:#"Apple"];
[self presentViewController:webViewController animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Here is code of WebViewController.h:
#import <UIKit/UIKit.h>
#interface WebViewController : UIViewController <UIWebViewDelegate>
{
NSURL *theURL;
NSString *theTitle;
IBOutlet UIWebView *webView;
IBOutlet UINavigationItem *webTitle;
}
- (id)initWithURL:(NSURL *)url;
- (id)initWithURL:(NSURL *)url andTitle:(NSString *)string;
- (IBAction) done:(id)sender;
#end
And here is code of WebViewController.m:
#import "WebViewController.h"
#interface WebViewController ()
#end
#implementation WebViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
webTitle.title = theTitle;
NSURLRequest *requestObject = [NSURLRequest requestWithURL:theURL];
[webView loadRequest:requestObject];}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (id)initWithURL:(NSURL *)url andTitle:(NSString *)string {
if( self = [super init] ) {
theURL = url;
theTitle = string;
}
return self;
}
-(id)initWithURL:(NSURL *)url {
return [self initWithURL:url andTitle:nil];
}
- (IBAction) done:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
webView.delegate = nil;
[webView stopLoading];
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
You need to instantiate the webView at some point. I suggest you change your viewDidLoad to this:
- (void)viewDidLoad
{
[super viewDidLoad];
webView = [[UIWebView alloc] init];
webTitle.title = theTitle;
NSURLRequest *requestObject = [NSURLRequest requestWithURL:theURL];
[webView loadRequest:requestObject];
}
Since your webView is nullat the start of the method, it needs to be created before you can load any Requests. Just declaring it in the header file is not enough, thats why you need webView = [[UIWebView alloc] init];.
EDIT:
Of course, you could also put that line into your ìnitWithURL:andTitle: method, where the other instantiations take place.
In my app, I have viewcontrollers that include webviews with activity indicators and they work fine. Now,in a new viewcontroller with a webview and activity indicator I am getting some weird behavior. In the simulator the view loads but the activity indicator remains spinning even when the view is finished loading. I copied everything exactly from another viewcontroller with webview and activity indicator that is working, but the weird behavior is still their. The URLs are just regular small html files so it's not like either one will take a long time to load. I don't know if this is a glitch in xcode (ver 5.0), or most likely something I am overlooking in the code. The code for the working viewcontroller is below:
#import "ProgramPDFViewController.h"
#interface ProgramPDFViewController ()
#end
#implementation ProgramPDFViewController
#synthesize webView;
#synthesize activity;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[TestFlight passCheckpoint:#"PDFProgram-info-viewed"];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:#" " style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButtonItem;
// Do any additional setup after loading the view.
NSString *httpSource = #"<myURL>";
NSURL *fullUrl = [NSURL URLWithString:httpSource];
NSURLRequest *httpRequest = [NSURLRequest requestWithURL:fullUrl];
[webView loadRequest:httpRequest];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)webViewDidStartLoad:(UIWebView *)WebView
{
[activity startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)WebView
{
[activity stopAnimating];
activity.hidden = TRUE;
}
#end
The code from the one with the weird behavior is below:
#import "ComitteeMeetingsViewController.h"
#interface ComitteeMeetingsViewController ()
#end
#implementation ComitteeMeetingsViewController
#synthesize webView, activity;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[TestFlight passCheckpoint:#"CommitteMeetings-info-viewed"];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:#" " style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButtonItem;
NSString *httpSource = #"<myOtherURL>";
NSURL *fullUrl = [NSURL URLWithString:httpSource];
NSURLRequest *httpRequest = [NSURLRequest requestWithURL:fullUrl];
[webView loadRequest:httpRequest];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)webViewDidStartLoad:(UIWebView *)WebView
{
[activity startAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)WebView
{
[activity stopAnimating];
activity.hidden = TRUE;
}
#end
Are you sure the methods are actually called?
Did you set the webView's delegate and included UIWebViewDelegate in the header file?
For troubleshooting: try adding
NSLog(#"webViewDidStartLoad");
and
NSLog(#"webViewDidFinishLoad");
to the corresponding methods and see if they show up in the log
I'm using FusionCharts on an iOS application.
Currently I have a view controller with two different UIWebViews that are loading two different charts from different html files.
The problem is that both charts are rendered but one of them is invisible as you can see in the screenshot.
It only works with one chart at a time. How can I fix this?!
screenshot
The problem this issue is is with UIWebView it self for clear explanation check out below link
http://double-slash.net/2010/10/18/using-multiple-ios-uiwebview-objects/ It can be fixed in two way by adopting a spin lock mechanism or increasing rendering time of run loop by customize the UIWebview.
enter code here
#interface FCXTCustomWebView ()
#property (assign) id idelegate;
#end
#implementation FCXTCustomWebView
- (id)init
{
self = [super init];
if (self)
{
self.delegate = self;
}
return self;
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.delegate = self;
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.delegate = self;
}
return self;
}
- (void)setDelegate:(id<UIWebViewDelegate>)delegate
{
_idelegate = delegate;
}
- (void)stopRunLoop
{
CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
CFRunLoopStop(runLoop);
}
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[self performSelector:#selector(stopRunLoop) withObject:nil afterDelay:.01];
if ([_idelegate respondsToSelector:#selector(webView:didFailLoadWithError:)])
{
[_idelegate webView:webView didFailLoadWithError:error];
}
}
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([_idelegate respondsToSelector:#selector(webView:shouldStartLoadWithRequest:navigationType:)])
{
return [_idelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}
else
{
return YES;
}
}
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[self performSelector:#selector(stopRunLoop) withObject:nil afterDelay:.01];
if ([_idelegate respondsToSelector:#selector(webViewDidFinishLoad:)])
{
[_idelegate webViewDidFinishLoad:webView];
}
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
[self performSelector:#selector(stopRunLoop) withObject:nil afterDelay:.1];
if ([_idelegate respondsToSelector:#selector(stopRunLoop)])
{
[_idelegate webViewDidStartLoad:webView];
}
}
- (void) loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
{
[super loadHTMLString:string baseURL:baseURL];
CFRunLoopRunInMode((CFStringRef)NSDefaultRunLoopMode, 1.5, NO);
}
#end
This reply might be too late. I encountered the same issue with HighCharts.
You need not subclass UIWebView. You need to have different Javascript files for the each graph. That would work.
i want my code to allow me to pick multiple items via my ipod library. Currently I am able to select one song. i want to modify my code to allow for a series of songs to be added to the que. Currently selecting YES for "pick multiple items" allows for selection however playback consists of only one song. the first selected.
How may I change this. I have included a sample of my code below...
#implementation ProjectViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[self performSelector:#selector(presentLibrary) withObject:nil afterDelay:0.1];
[super viewDidLoad];
}
-(void)presentLibrary
{
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
// picker.navigationController.delegate = self;
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (#"Select any song from the list", #"Prompt to user to choose some songs to play");
//[self.view addSubview:picker.view];
[self presentModalViewController: picker animated: YES];
//picker.view.frame = CGRectMake(picker.view.frame.origin.x, 0, picker.view.frame.size.width, picker.view.frame.size.height);
[picker release];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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;
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
- (void)dealloc {
[super dealloc];
}
- (IBAction)onlaunch:(id)sender
{
xxxxxxxx ViewController *viewController = [[xxxxxxxxxViewController alloc] init];
[self presentModalViewController:viewController animated:YES];
[viewController release];
}
-(void)viewDidAppear:(BOOL)animated
{
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissModalViewControllerAnimated: NO];
//[mediaPicker.view removeFromSuperview];
//NSURL *url = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"screen1.mp4"]]; //test.caf
NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];
NSLog(#"url:%#",url);
[[ShareInfo shareduserInfoManager] setSongUrl:url];
[self goToxxxxxxxxxyView];
}
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker
{
[self dismissModalViewControllerAnimated: NO];
[[ShareInfo shareduserInfoManager] setSongUrl:nil];
[self goToxxxxxxxxxView];
}
-(void)goToxxxxxxxView
{
xxxxxxxxxxxxxx *viewController = [[xxxxxxxxxxxxxxxr alloc] init];
[self presentModalViewController:viewController animated:YES];
[viewController release];
}
#end
Instead of
NSURL *url = [[mediaItemCollection.items objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];
Which is selecting the 1st song,
try
if (mediaItemCollection)
[musicPlayer setQueueWithItemCollection: mediaItemCollection];