Activity Indicator Doesn't Stop/Start Properly - iphone

EDIT: Problem Solved!
For others, To fix it, simply right click the WebView, click the "delegate" circle, and drag it to "File's Owner" on the left side.
Thanks for the help
--I'm fairly new to app developing, I'm in my first semester actually. Since it's a brand new course, the instructor knows very little as well. Therefore I have complete permission to ask for help on this. Thanks!
On to my question...
I want to include an activity indicator in my app as my WebView starts and stops loading, simply enough. At this point, it will animate. However, my problem is that it starts before the WebView starts loading anything, and also doesn't ever stop. My current code is this:
- (void)webViewDidStartLoad:(UIWebView *)webView {
[activity startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activity stopAnimating];
Other than that, I have it set up in the header...
IBOutlet UIActivityIndicatorView *activity;
And as far as I can tell, set up rather properly. Oh, also, I do have "Animated" checked and "Hide When Stopped" checked in the .xib file.
UPDATE: NSLogs and breakpoints show that the methods aren't being called.
I am a highly visual learner, so, I will need to see what I am missing, unless it is a problem in the interface. Thanks...
Any help is much appreciated

Do you have your webView correctly connected to the delegate? Toss in an NSLog or a couple breakpoints and make sure that your functions are being called.

You can put a break point in your code to see if the webViewDidFinishLoading is called. I'm guessing it is not being called. There is another delegate methods you should implement (see UIWebViewDelegate Protocol Reference), called webView:didFailLoadWithError:. Implement that and put a break point inside it. Let us know what happens.

Did you see the apple developer examples?
Apple Developer Example Webview

Related

objective-c: help me understand views and modal transition

I'm lacking a serious understanding of how modal transitions work, so please do not leave the simplest answer out of this.
I have two views with their own view controllers set up in storyboard. A button on the main-menu leads to other-view. I set up this transition purely via ctrl-click and selecting the modal transition. I also have a button leading from the other-view back to the main-menu, set up similarly.
To further my understanding of these transitions I decided that I want the main menu to play a sound when it loads up, but only the first time i hit run, and not again when i go hit the button the other-view to go back to menu-view.
in my menu-view I have a private property BOOL
#interface MainMenuViewController ()
#property BOOL menuSoundPlayed;
#end
and my viewDidLoad...
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.menuSoundPlayed){
//sound setup code omitted for clarity
AudioServicesPlaySystemSound(mySound);
self.menuSoundPlayed = YES;
}
}
can someone help me understand why the menu sound plays every time main-menu view loads? I do acknowledge that the menuSoundPlayed is never really initialized, but I dont know where I would even do that.
side-note: I love that apple gives us all these conveniences like story-board, but I almost wish it was easier to see all the code behind these things, so i could actually understand what was going on when i 'segue' between views.
Anyways, thank you!
I did a bit more researching and answered my own question.
In the situation I had before (described in my question) I had the code
[self performSegueWithIdentifier:#"mainMenuSegue" sender:sender];
being executed, which as commenters described, starts a new instance of my main-menu.
What i wanted was to return to the main-menu instance already created.
To do this the following code is necessary (with your own completion block obviously):
[self dismissViewControllerAnimated:YES
completion:^{
NSLog("view dismissed");
}];

UISegmentedControl Problem setting hidden

Hi I regulary created using IB one UISegmentedControl that I called showAllSwitch.
If I try to do [showAllSwitch setHidden:YES]; nothing happens!
Why? How can I do to hide it?
Where are you calling setHidden? if it is being called before it is added to the view, then there could be problems. Try calling it in viewDidAppear and see it that works. If it doesn't either the segmentedControl is not connected correctly in IB, or there is a rather big problem that we are missing.
Hiding an object is relatively straight forward. So if there is a problem then its something simple. You need to just go through some basic diagnostic steps:
Verify that your segmented control is actually connected to the correct outlet in IB. Really. Go look. Even if you are sure. Go look again.
Verify that the line where you are hiding it is being called. Add an NSLog just after and see if it shows up when it should.
Make sure that the hide command is not getting sent too soon. If its being sent in ViewDidLoad try setting it up in ViewDidAppear.

AVFoudationFramework: StillImageCapture: how to exit from AVFF?

I have a question or two about using AVFoundationFramework in XCode.
I downloaded AVCamDemo source code. I am trying to leverage the code in my app to replace UIImagePickerController (because it is slow) with the AVFF functionality. However, I cannot figure out how to exit the AVFF code when "Done" button is tapped in the UI. My app will provide the Done button.
Specifically, I need to know:
What do i need to stop the capture session? Just [session stopRunning] ??
My app's ViewController will invoke the AVFF, and will provide the "Done" button in the view controller that I will create for the AVFF functionality. When the user taps the "Done" button, I need to stop the capture process and exit back to my app. I am not sure how this can be done.
Any help will be highly appreciated.
Regards, Sam.
Yes. Although you may also want to ensure you turn the video torch off if you had turned it on, and if you called lockForConfiguration on the device you should be sure to unlock it.
There is no "exiting". If you presented your view controller using presentModalViewController:animated:, use dismissModalViewControllerAnimated:. If you pushed it onto a UINavigationController, pop it back off. If you did it some other way, dismiss it in the way appropriate for that method.
regarding your question on AVFoundationFramework:
I don't exactly understand what you are not succeeding to do. Some general options:
[session stop] will stop capturing.
You can play with the AVCaptureVideoPreviewLayer layer - that's what actually shows the camera preview.
All the ui code is in AVCamViewController - so you can just pop it from the stack, or remove it from superview - which ever is correct in your code.
If these don't help, please try to elaborate further on the problem, and perhaps supply some code.
Cheers,
Oded.

iPhone UIViews sleeping/dying after being brought back into view

I need some help. This seems to be a common problem I am having when am adding and changing views in my coding. And I would love to learn what I am doing wrong.
Currently I am adding and removing views using the following calls from my view controller:
[startView removeFromSuperview];
[self addSubview:secondView];
and then doing the opposite again to go back.
[secondView removeFromSuperview];
[self addSubview:startView];
I am fine up to this point.
But the problem I have is that when I then decide to go back to 'startView" and call the first code that I have above for the second time.
My View loads but very little works.
None of my methods are called, there is no animation and the view is shown but it is "dead" or "asleep". And I have no idea why!
I am basically adding a view, removing it, then adding it again and everything breaks.
Can anyone give me a hand as to what might be happening? is it that ViewDidLoad doesn't fire the second time it's loaded? or something like that?
I would much appreciate it.
I may have figured it out So don't worry!
I had a flag hidden in my code somewhere that was stopping my methods from firing.
Sorry!

Crash when calling stringByEvaluatingJavaScriptFromString on UIWebView from button

I can't find any documentation to confirm this, but it appears that you can only call the method stringByEvaluatingJavaScriptFromString in overridden methods from a UIWebView delegate. Can anyone confirm this?
Here's what I've tried. I setup a button on a view, link it to a method on my viewcontroller, and make sure it works fine. My view has a UIWebView control on it as well. If I run the project on the simulator or on the iPhone, there are no issues. Then I add this code to the button's method.
[theWebView stringByEvaluatingJavaScriptFromString:#"alert('Hi there!');"];
When I run the project, I can click the button and see the 'Hi there' prompt and I can click OK to dismiss it. Usually 4-5 seconds later the simulator crashes. I occasionally see the "__TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__" error, but not consistently; sometimes there's no error. It also doesn't always crash the first time. Sometimes I go to another page, and then try it again, and it crashes.
If I put the same code in the webPageDidFinishLoad event it works fine. But I'd like the code to be called when the user demands it so that event doesn't suit my needs.
I'm open to a workaround if you have any ideas? Thanks in advance!
I still don't know the exact reason this didn't work, but I found I could rewrite my code to get called during the UIWebView delegate methods instead.