Stop animation of multiple UIActivityIndicatorView - iphone

I have some dynamic webview and activity indicator.
All is working fine when webview is loaded. But if i tried to stop the activity indicator after the loading is completed, only one indicator is stop spinning not all.
So how can i solve this problem :
I am using following code
-(void)myMethod{
for (int i=0; i<count; i++)
{
//Create webview one by one
webView.tag=i;
//Create a activityindicator
activityIndicatorView.tag=i;
[activityIndicatorView startAnimating];
[webView addSubView: activityIndicatorView];
[self.view addSubView:webView];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if(webView.tag==0)
{
[activityIndicatorView setHidden:YES];
}
else if (webView.tag==1)
{
[activityIndicatorView setHidden:YES];
}
else if (webView.tag==2)
{
[activityIndicatorView setHidden:YES];
}
else if (webView.tag==3)
{
[activityIndicatorView setHidden:YES];
}
}

Because you are actually only loading data on one single web view instance. Your initial loop always uses the very same web view. And, likewise, you keep using and starting the very same activity-indicator instance. Just because you assign a new tag to it, it will not create a new instance for you.

Related

simulate button pressed by single tap

as titled, would like to tap the screen, screen will be a bit dark translucent, while the finger leaves the screen, the screen turn back to normal, which is similar as UIButton does.
In this case, I know UIButton is much easier, but here is just a sample
my codes as the following:
- (IBAction)tapped:(UITapGestureRecognizer *)sender
{
UIView * tintView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:tintView];
switch (sender.state) {
case UIGestureRecognizerStateRecognized: {
[tintView setBackgroundColor:[UIColor colorWithRed:.25 green:.25 blue:.25 alpha:.5]];
NSLog(#"begin");
}
default: {
[tintView setBackgroundColor:[UIColor clearColor]];
NSLog(#"ended");
}
}
}
But, when tapping the screen, it won't be changed as above codes looks, although begin and ended are captured in the console.
If interchanging those codes between case and default like
switch (sender.state) {
case UIGestureRecognizerStateRecognized: {
[tintView setBackgroundColor:[UIColor clearColor]];
NSLog(#"begin");
}
default: {
[tintView setBackgroundColor:[UIColor colorWithRed:.25 green:.25 blue:.25 alpha:.5]];
NSLog(#"ended");
}
}
begin and ended could be shown in the console, but the screen will be darker and darker when tapping, never back to normal, clear color.
What's wrong with my codes? How to make it happen?
Thanks!
[self performSelector: withObject: afterDelay:] would be the usual way to accomplish something like this.
You'd setup your method which dismisses the darkened view separately, then reference it as the selector
[self performSelector:#selector(methodWhichDismissesDarkView:) withObject:nil afterDelay:0.2]
call this immediately after you darken the view, and 0.2 seconds later it will fire.
To really do it right though, make sure you can gracefully handle interruptions that happen during the delay by using this:
[NSObject cancelPreviousPerformRequestsWithTarget:self];
Which will cancel the pending action when the app no longer needs to handle it.
by following #ryancumley 's hint, below is updated codes.
#property (strong, nonatomic) UIView * tintView;
#synthesize tintView;
- (IBAction)tapped:(UITapGestureRecognizer *)sender
{
switch (sender.state) {
case UIGestureRecognizerStateRecognized: {
[self.tintView setBackgroundColor:[UIColor colorWithWhite:0.000 alpha:0.150]];
[self performSelector:#selector(setTintView:) withObject:nil afterDelay:.25];
NSLog(#"begin");
}
default: {
break;
NSLog(#"ended");
}
}
}
- (void)setTintView:(UIView *)tintView
{
[self.tintView setBackgroundColor:[UIColor colorWithRed:.25 green:.25 blue:.25 alpha:0]];
}
It works finally and looks like tapping a button. But, NSLog(#"ended") not triggered.
Why my original can't work?
Is this updated a correct approach or workaround?

How to Implement UIProgressView in iphone sdk

I have this code in a button click [NSThread detachNewThreadSelector: #selector(spinBegininapp) toTarget:self withObject:nil]; to show a activity indicator for user that the background thread is running ,i put this code to enable the activity-indicator
- (void)spinBegininapp
{
_activityindictor.hidden = NO;
}
and it works fine,when i click the button it shows the activity-indictor animating ,when the thread goes it hides the activity-indicator,but my need is to show a progressView instead of activity-indicator,it progresses according to the thread,and if the thread finishes it need to reach progress completely and self hide.is that possible .
#pragma mark - Loading Progress
static float progress = 0.0f;
-(IBAction)showWithProgress:(id)sender {
progress = 0.0f;
_progressView.progress = progress;
[self performSelector:#selector(increaseProgress) withObject:nil afterDelay:0.3];
}
-(void)increaseProgress {
progress+=0.1f;
_progressView.progress = progress;
if(progress < 1.0f)
[self performSelector:#selector(increaseProgress) withObject:nil afterDelay:0.3];
else
[self performSelector:#selector(dismiss) withObject:nil afterDelay:0.2f];
}
-(void)dismiss {
[self progressCompleted];
}
now call the following function whenever/where ever you want to show progress
[self showWithProgress:nil];
progress range lies between 0.0 and 1.0
1.0 means 100%
you can add a progress view no doubt but usually it used for definite quantities like time or data.. for eg. If you are downloading a 2mb file then you can always tell how much data you have downloaded and show the in the progress view as a factor. So if something similar is happening inside your thread you can use this..
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:whateverStyle];
progressView.progress = 0.75f;
[self.view addSubview: progressView]
[progressView release];
you just need to update your progress as the value changes.... hoping this helps.

iPhone - How to have a custom browser be able to detect if back/forward buttons need to be enabled/disabled

Hey guys! I have a tumblr app that I am developing, and I have a button that pushes a modal view that contains a webview and a toolbar on the bottom with refresh, back, forward and done buttons. The back forward and refresh buttons work, however I want to be able to tell if the webview can actually go back/forward and if not, disable the button..I have tried the code below, and the image nor the enable/disable changes.
- (IBAction)refreshPage {
[signUpWebView reload];
}
- (IBAction)goBack {
[signUpWebView goBack];
}
- (IBAction)goForward {
[signUpWebView goForward];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
// Enable or disable back
if ([signUpWebView canGoBack]) {
[backOnePage setEnabled:YES];
backOnePage.image = [UIImage imageNamed:#"backButton"];
} else {
[backOnePage setEnabled:NO];
backOnePage.image = [UIImage imageNamed:#"backButtonDisabled"];
}
// Enable or disable forward
if ([signUpWebView canGoForward]) {
[forwardOnePage setEnabled:YES];
forwardOnePage.image = [UIImage imageNamed:#"forwardButton"];
} else {
[forwardOnePage setEnabled:NO];
forwardOnePage.image = [UIImage imageNamed:#"forwardButtonDisabled"];
}
}
Any recommendations would be greatly appreciated!
I recommend binding the forward and backward button directly to the UIWebview.
Automatically enable and disable like this:
- (void)webViewDidStartLoad:(UIWebView *)mwebView {
backButton.enabled = (webView.canGoBack);
forwardButton.enabled = (webView.canGoForward);
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
backButton.enabled = (webView.canGoBack);
forwardButton.enabled = (webView.canGoForward);
}
When you first initialize your webView, try starting it with a request, like this:
[signUpWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]];
So you're initializing the webView with loadRequest: instead of loadHTMLString:, or something similar.

What is the problem with the back button in my UIWebView?

I have an issue in my application that i wrote coding for the back button in my webView setEnabled = NO, but when the application is launched and webViewDidFinishLoad the back button setEnabled = YES. I tried all possibility to set the back button enabled is equal false but it not works.
-(IBAction) backButton : (id) sender{
backTapped = YES;
[webView goBack];
}
-(IBAction) fwdButton : (id) sender{
forwardTapped = YES;
[webView goForward];
}
- (void)webViewDidStartLoad:(UIWebView *)thisWebView{
NSLog(#"webViewDidStartLoad");
[progressWheel startAnimating];
progressWheel.hidden = NO;
if(!backTapped){
back.enabled = NO;
}
if (!forwardTapped) {
forward.enabled = NO;
}
}
- (void)webViewDidFinishLoad:(UIWebView *)thisWebView
{
[progressWheel stopAnimating];
progressWheel.hidden = YES;
if (!backTapped) {
[back setEnabled:thisWebView.canGoBack];
back.showsTouchWhenHighlighted = YES;
}
if (!forwardTapped) {
[forward setEnabled:thisWebView.canGoForward];
forward.showsTouchWhenHighlighted = YES;
}
}
I can't actually quite understand the problem you are having, but I can see two potential issues:
1) You set backTapped and forwardTapped to YES, but never set them to NO anywhere.
2) Perhaps you don't have "back" or "forward" buttons wired in you xib - if they are nil then back.enabled = NO will do nothing.
Edit:
This logic seems backwards:
if (!backTapped)
back.enabled = NO;
In your code you set backTapped to YES, then this code is hit so !backTapped is ! YES which is NO.
Try
if (backTapped)
back.enabled = NO;

Customizing UIPickerView

I have a requirement where UIPickerView should be customized. The picker view should look something like this:
The application which has customized the pickerView similarly is:
http://itunes.apple.com/us/app/convert-the-unit-calculator/id325758140?mt=8
I have tried removing the default pickerView selection bar by resetting the property showsSelectionIndicator of UIImagePicker and adding a overlay view. But the problem is, the overlay view should be transparent so that the wheel behind it is visible. But the other application somehow does it even though the selection bar is not transparent.
Any ideas on how to achieve this feat?
Thanks and Regards,
Raj
You're going to have to write your own from scratch on this one. UIPickerview isn't customizable. At. All. Sucks, but that's how it is. I'd start out creating a uitableview and layering a frame around it, and trying to mimic uipickerview.
I think you can print the subviews under the picker and modify them.
The UIPickerView create subviews after the data is first loaded.
With performSelecter:WithObject:afterDelay:, you can remove them or insert whatever you need.
- (void)viewDidLoad
{
[super viewDidLoad];
[self refreshClock];
[timePicker_ performSelector:#selector(leakSelf) withObject:nil afterDelay:0];
[self performSelector:#selector(setupTimePicker) withObject:nil afterDelay:0];
}
- (void)setupTimePicker {
[[timePicker_ subviewOfClass:NSClassFromString(#"_UIPickerViewTopFrame")] removeFromSuperview];
CGRect frame = timePicker_.frame;
frame.size.width += 20;
frame.origin.x -= 10;
timePicker_.frame = frame;
}
#implementation UIView(UIViewDebugTool)
- (void)leakSubview:(UIView*)subroot atDepth:(NSUInteger)dep {
DLog( #"trace sub view[%u] %#", dep, [subroot description] );
CALayer* layer = subroot.layer;
for( CALayer* l in layer.sublayers ) {
DLog( #"layer[%u] %#", dep, l );
}
for( UIView* v in subroot.subviews ) {
[self leakSubview:v atDepth:dep+1];
}
}
- (void)leakSelf {
NSUInteger dep = 0;
[self leakSubview: self atDepth:dep];
}
#end