Activity Indicator show and hide in splash Image & UITableView - iphone

i want to add activity indicator & show at when i select didSelectRowAtIndexPath and hide at while detailView page displayed...plz help anyone.... and Give any sample Code.

-(void)showActivityViewer {
self.activityView = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.window.bounds.size.width, self.view.window.bounds.size.height)] autorelease];
activityView.backgroundColor = [UIColor blackColor];
activityView.alpha = 0.5;
self.activityWheel = [[[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(self.view.window.bounds.size.width / 2 - 12, self.view.window.bounds.size.height / 2 - 12, 24, 24)] autorelease];
activityWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
activityWheel.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[activityView addSubview:activityWheel];
[self.view.window addSubview: activityView];
[[[activityView subviews] objectAtIndex:0] startAnimating];
}
-(void)removeActivityViewer {
[activityWheel removeFromSuperview];
[activityView removeFromSuperview];
self.activityWheel = nil;
self.activityView = nil;
}

MBProgressHUD does exactly that! Check out https://github.com/jdg/MBProgressHUD

Related

iOS: How do you make two UIViews auto fill space?

I am trying to programmatically make two views share width of a parent view. I have tried either using an init for the subviews and an initWithFrame, but in either case, I can't get the stretching to work correctly. In the example below, I am expecting to see a red window spanning half of the width of the screen and a green window filling the other half. What am I missing?
self.view = [[UIView alloc] initWithFrame:self.window.frame];
self.left = [[UIView alloc] init];
self.right = [[UIView alloc] init];
[self.left setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight)];
[self.right setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight)];
[self.view setBackgroundColor:[UIColor blueColor]];
[self.left setBackgroundColor:[UIColor redColor]];
[self.right setBackgroundColor:[UIColor greenColor]];
[self.left setContentMode:UIViewContentModeScaleToFill];
[self.right setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview:self.left];
[self.view addSubview:self.right];
[self.view setAutoresizesSubviews:YES];
[self.window addSubview:self.view];
Thanks!
You never set the initial frame of the 2 views.
This code is tested and working in a UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect fullFrame = self.view.frame;
// position left view
CGRect leftFrame = fullFrame;
leftFrame.size.width = leftFrame.size.width / 2;
self.left = [[UIView alloc] initWithFrame:leftFrame];
// position right view
CGRect rightFrame = leftFrame;
rightFrame.origin.x = rightFrame.size.width;
self.right = [[UIView alloc] initWithFrame:rightFrame];
[self.left setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight)];
[self.right setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight)];
[self.view setBackgroundColor:[UIColor blueColor]];
[self.left setBackgroundColor:[UIColor redColor]];
[self.right setBackgroundColor:[UIColor greenColor]];
[self.left setContentMode:UIViewContentModeScaleToFill];
[self.right setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview:self.left];
[self.view addSubview:self.right];
[self.view setAutoresizesSubviews:YES];
}
Try to set some initial frames of the subviews which you add to the main view. This should help:
self.left.frame = CGRectMake(0, 0, self.window.frame.size.width/2, self.window.frame.size.height);
self.right.frame = CGRectMake(self.window.frame.size.width/2, 0 , self.window.frame.size.width/2, self.window.frame.size.height);

Preload circle for UITableView

I search for a lot forums but nothing found, my problem is that
I need preload some data from the web to load to the UITableView.
I saw some apps solved this problem, when show UITableView they shows "waiting circle" as modal view and after data is loaded just hide this circle.
Is there simple solution to do this?
What I need to do?
What kind of Request do I need: synchronius or asynchronius?
How to show this circle, do I need to show animatedGif or there is some internal/external control for this?
You need to make a NSThread for your "waiting circle"-(Activity Indicator).
1)Threads How do I create an NSThread that isn't the main thread.
2)Activity Indicator How to use activity indicator view.
- (void)showWaitingView {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = #"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];
[progressInd release];
[waitingLable release];
[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
}
- (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];
}

iPhone: Progress Indicator

In my app when I download something from service, I show progress indicator:
- (void)setupProgressIndicator {
MBProgressHUD *progressHUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:progressHUD];
self.progressIndicator = progressHUD;
[progressHUD release];
}
[self.progressIndicator show:YES];
My view has Navigation Bar which I setup in my AppDelegate, and when indicator is shown, I still can tup on Navigation Bar Buttons...Can MBProgressHUB cover whole screen ??? Because I don't want to disable buttons on sync start and than make them enable on sync finish...I think indicator should cover whole screen. Any ideas ? Thanks...
Here is my implementation use it if you want
Put it in appDelegate and use from anywhere in the application.
#pragma mark -
#pragma mark Waiting View
- (void)showWaitingView {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = #"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];
[progressInd release];
[waitingLable release];
[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
}
- (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];
}
usual thing is to add an transparent view cover the entire screen and that will capture touch event. or you can make your HUD the size of the screen, with visible widget only in the center.
- (IBAction)showWithCustomView:(id)sender {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"37x-Checkmark.png"]] autorelease];
HUD.customView.frame=CGRectMake(0, 0, 320, 460);//Ur answer
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = #"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:3];
}

How can I programmatically position a view using relative points?

What is the best way to position a view relative to the size of its superview, when the bounds of the superview are not yet known?
I am trying to avoid hard-coding coordinates if it is at all possible. Perhaps this is silly, and if so, that's a perfectly acceptable answer.
I've run into this many times when working with custom UI. The most recent example is that I'm trying to replace the UINavigationItem plain-text title with a custom view. I want that view to fill the superview, but in addition, I want a UIActivityIndicatorView on the right side, inset about 2 pixels and centered vertically. Here's the code:
- (void) viewDidLoad
{
[super viewDidLoad];
customTitleView = [[UIView alloc] initWithFrame:CGRectZero];
customTitleView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
titleLabel.lineBreakMode = UILineBreakModeWordWrap;
titleLabel.numberOfLines = 2;
titleLabel.minimumFontSize = 11.0;
titleLabel.font = [UIFont systemFontOfSize:17.0];
titleLabel.adjustsFontSizeToFitWidth = YES;
[customTitleView addSubview:titleLabel];
spinnerView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinnerView.center = CGPointMake(customTitleView.bounds.size.width - (spinnerView.bounds.size.width / 2) - 2,
customTitleView.bounds.size.height / 2);
spinnerView.hidesWhenStopped = YES;
[customTitleView addSubview:spinnerView];
self.navigationItem.titleView = customTitleView;
[customTitleView release];
}
Here's my problem: at the time that this code runs, customTitleView.bounds is still zeroes. The auto-resizing mask hasn't had a chance to do its thing yet, but I very much want those values so that I can compute the relative positions of other sub-views (here, the activity indicator).
Is this possible without being ugly?
The only reason customTitleView.bounds has zero width and height is because you've initialized it that way by using CGRectZero. You can initialize the view with any nonzero size and then define its subviews in relation to that arbitrary size. As long as you've defined the autoresizing behaviors of the subviews properly, their layout will be adjusted appropriately when the frame of the superview changes at runtime.
For example:
- (void) viewDidLoad
{
[super viewDidLoad];
customTitleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
customTitleView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
titleLabel = [[UILabel alloc] initWithFrame:customTitleView.bounds];
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
titleLabel.lineBreakMode = UILineBreakModeWordWrap;
titleLabel.numberOfLines = 2;
titleLabel.minimumFontSize = 11.0;
titleLabel.font = [UIFont systemFontOfSize:17.0];
titleLabel.adjustsFontSizeToFitWidth = YES;
[customTitleView addSubview:titleLabel];
[titleLabel release];
spinnerView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinnerView.center = CGPointMake(customTitleView.bounds.size.width - (spinnerView.bounds.size.width / 2) - 2,
customTitleView.bounds.size.height / 2);
spinnerView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
spinnerView.hidesWhenStopped = YES;
[customTitleView addSubview:spinnerView];
[spinnerView release];
self.navigationItem.titleView = customTitleView;
[customTitleView release];
}

Custom back button click event on pushed view controller

I have pushed view controller and load WebView and Custom rectangular rounded button on right down left corner into view using programmatic way.
-(void)loadView {
CGRect frame = CGRectMake(0.0, 0.0, 480, 320);
WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease];
WebView.backgroundColor = [UIColor whiteColor];
WebView.scalesPageToFit = YES;
WebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin);
WebView.autoresizesSubviews = YES;
WebView.exclusiveTouch = YES;
WebView.clearsContextBeforeDrawing = YES;
self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
self.roundedButtonType.frame = CGRectMake(416.0, 270.0, 44, 19);
[self.roundedButtonType setTitle:#"Back" forState:UIControlStateNormal];
self.roundedButtonType.backgroundColor = [UIColor grayColor];
[self.roundedButtonType addTarget:self action:#selector(back:) forControlEvents:UIControlEventTouchUpInside];
self.view = WebView;
[self.view addSubview: self.roundedButtonType ];
[WebView release];
}
This is action that I have added as back button of navigation.
-(void)back:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)viewDidUnload{
self.WebView = nil;
self.roundedButtonType = nil;
}
-(void)dealloc{
[roundedButtonType release];
[super dealloc];
}
Here, When Back button click then it is showing previous view but application got stuck in that view and GDB shows Program received signal :EXC_BAD_ACCESS message.
how resolve this issue?
Thanks,
You have -autorelease'd WebView here:
WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease];
but then you -release it again!
[self.view addSubview: self.roundedButtonType ];
[WebView release];
Try to remove one of the releases.
Also,
self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
unless roundedButtonType is declared as #property(assign,...), you don't need to send the -retain message. And it's better to setup the frame, title, etc. before assigning to self.roundedButtonType, because every call to self.roundedButtonType is not free.