Inconsistent behavior with Activity Indicator in iOS - ios

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

Related

iOS handoff from phone to macbook safari/chrome

I want to send a URL from my app to open on a laptop web browser using handoff. I have added the activity type to my app's NSUserActivityTypes. here is my code so far:
- (void)startHandoff {
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:#"com.me.browse"];
activity.webpageURL = [NSURL URLWithString:_wakeUrl];
[activity becomeCurrent];
}
It doesn't seem to be appearing on my dock - does it need a special Activity Type if you want to use safari?
Ok after tests, it seems that you need to declare the NSUserActivity as a instance Variable :
So this does not work:
#interface TestViewController () {
}
#end
#implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
//init hand off
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:#"com.app.browse"];
activity.webpageURL = [NSURL URLWithString:#"http://www.stackoverflow.com"];
[activity becomeCurrent];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
But this works fine:
#interface TestViewController () {
NSUserActivity *activity;
}
#end
#implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
//init hand off
activity = [[NSUserActivity alloc] initWithActivityType:#"com.app.browse"];
activity.webpageURL = [NSURL URLWithString:#"http://www.stackoverflow.com"];
[activity becomeCurrent];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Not sure why though, I'm looking into it now

PDF in UIWebView not working

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...

Only black screen in my UIWebView

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.

Can't hide HUD in UIWebView for IOS project

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;

iOS PopOver with Webview

I am trying to build a pop over that displays a webView. So far, I have a button that when pressed, generates a pop over but the web view does not display. Using NSlog, I can see that the viewDidLoad method is firing. Here is the code I have so far:
In the popover.h file:
#interface PopUpViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIWebView *liveTimingPopUp;
#end
In the popover.m file:
#import "PopUpViewController.h"
#interface PopUpViewController ()
#end
#implementation PopUpViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadWebView];
}
- (void) loadWebView
{
// Do any additional setup after loading the view.
NSString *fullURL = #"www.google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_liveTimingPopUp loadRequest:requestObj];
[self loadView];
NSLog(#"PopUpView Fired");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
In the control view containing the button that generates the popover .h file:
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController
{
UIInterfaceOrientation intOr;
// APICallsViewController *pendingApiCallsController;
}
#property (strong, nonatomic) IBOutlet UIWebView *liveVideoPage;
- (IBAction)liveTimingButton:(id)sender;
#property (strong, retain) UIPopoverController *popOver; //declare UIPopOver so that you have an object to work with
-(void) loadVideo;
#end
In the control view containing the button that generates the popover .m file:
#import "SecondViewController.h"
#import "PopUpViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self loadVideo];
}
- (void) loadVideo
{
NSString *fullURL = #"http://192.168.130.230:1935/live/camera.stream/playlist.m3u8";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_liveVideoPage loadRequest:requestObj];
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
intOr = self.interfaceOrientation;
if (intOr == UIInterfaceOrientationPortrait)
{
NSLog(#"portrait");
_liveVideoPage.frame = CGRectMake(10, 100, 600, 550);
}
else
{
NSLog(#"landscape");
_liveVideoPage.frame = CGRectMake(200, 100, 600, 550);
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)liveTimingButton:(id)sender
{
if ([_popOver isPopoverVisible]) {
[_popOver dismissPopoverAnimated:YES];
}
else
{
PopUpViewController *PUVC = [[PopUpViewController alloc]init];//instantiate ViewController for popOver's content
_popOver = [[UIPopoverController alloc] /* create Popover*/initWithContentViewController:PUVC]; //fills popover with PopUpViewController
_popOver.popoverContentSize = CGSizeMake(800, 250);
[_popOver presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //specifies where the popover is coming from...the liveTiming Bar button
}
}
#end
Any help would be greatly appreciated!
where is the webview supposed to come from? The VC gets not passed a xib name.. so the outlet will never bet set

Resources