iPhone: Progress Indicator - iphone

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];
}

Related

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];
}

Needed help in UIActivityIndicatorView - iPhone

Since i am new in iPhone i am having a litle problem. I want to use UIActivityIndicatorView in my application. Since I have bee succesfull using indicatorView but I want to display the IndicatorView with a Blur Background so that i could not click on the button on my Current activity.
Please Friends
Guide me to some tutorial or some code.
Thanks a bunch in advance
Here you go this is my implementation but you can modify. Post the code in app Delegate and use anywhere in you 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];
}
First, you have to add a view with a black background and alpha of 0.3 or something. Then add the activity indicator above the view.
// an example
[self.view addSubview:aSemiTransparentBlackView];
[self.view addSubview:activityIndicator];
can try this also:
-(UIAlertView *)showActivityIndicator :(NSString *)message
{
alertViewProgress = [[UIAlertView alloc] initWithTitle:message message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *activity =[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(120,50,37,37)];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[activity startAnimating];
[alertViewProgress addSubview:activity];
[activity release];
[alertViewProgress show];
return alertViewProgress;
}

problem i loading progress indicator in iphone sdk?

I want to get list from server it is taking some time So at that time I'm displaying progress indicator. My problem sometimes the progress indicator is appearing and some times it is not appearing. The code I used is
-(void)viewWillAppear:(BOOL)animated
{
[self loadprogressIndicator];
}
-(void)loadprogressIndicator
{
MessengerAppDelegate* appDelegate = (MessengerAppDelegate*) [ [UIApplication sharedApplication] delegate];
[appDelegate showWaitingView];
[NSThread detachNewThreadSelector:#selector(statusIndicatorForRefresh) toTarget:self withObject:nil];
}
-(void)statusIndicatorForRefresh
{
NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self performSelectorOnMainThread:#selector(loadList) withObject:nil waitUntilDone:NO];
[NSThread exit];
[pool release];
}
-(void)loadList
{
MessengerAppDelegate* appDelegate = (MessengerAppDelegate*) [ [UIApplication sharedApplication] delegate];
customerList = [appDelegate getCustomersArray];
[theTableView reloadData];
[appDelegate removeWaitingView];
}
And in appdelegate.m I implemeted these two methods
- (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];
}
Can anyone please help me. Happy Coding..
Thanks in advance.
Praveena..
You are doing all your activity on the main thread. Your app will appear to be blocked because you block the UI thread.
Also what is the use of launching an NSThread if all it does is call a method on your main thread and not even wait for it to complete? You are doing no multithreading at all.
Your app does this:
in main thread:
show waiting view
do 1 run loop cycle
do your data processing
hide waiting view
since your data processing is in the main thread you block everything there. You should do the processing in a secondary thread and leave the main thread for UI handling.

getting memory allocation at ActivityIndicator in Iphone sdk

Here I'm gettimg memory allocation problem at activity indicator and my code is:
- (id)init {
if (self = [super init]) {
self.title=#"Release Details";
contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor clearColor];
self.view = contentView;
[contentView release];
CGRect frame = CGRectMake(0,0, 320,1500);
containerView = [[UIView alloc] initWithFrame:frame];
webView = [ [UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
webView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"background1.png"]];
webView.delegate = self;
[containerView addSubview:webView];
CGRect activityViewframe = CGRectMake(20,8,20, 20);
progressInd = [[UIActivityIndicatorView alloc] initWithFrame:activityViewframe];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
progressInd.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[containerView addSubview:progressInd];
[progressInd startAnimating];
progressInd.hidden = NO;
[progressInd stopAnimating];
[self.view addSubview:containerView];
isFetch=YES;
}
return self;
}
-(void) displayInProgressRightBarButton
{
UIView* rightBarButtonView = [ [UIView alloc] initWithFrame:CGRectMake(270,5,45, 35)];
[rightBarButtonView addSubview:progressInd];
UIBarButtonItem* buttonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtonView];
self.navigationItem.rightBarButtonItem = buttonItem;
[rightBarButtonView release];
[buttonItem release];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[self displayInProgressRightBarButton];
[progressInd startAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[progressInd stopAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
Also I released the progressInd in dealloc eventhough it showing memory allocation at
progressInd = [[UIActivityIndicatorView alloc] initWithFrame:activityViewframe];
in init.
can anyone help me to solve this.
Anyone's help will be much Appreciated.
You can (and should) release it right after adding it to the container view:
[containerView addSubview:progressInd];
[progressInd release];
The same for the container view itself:
[self.view addSubview:containerView];
[containerView release];
The containing view will retain the subview for you, so you can release it right after adding it.

viewing tableViewLines on background of custom UIView

I have a viewController that has a tableView and a custom loading UIView that displays a loading message and spinner while the data of the tableView is being loaded.
The custom UIView has a red background that i can see, but i can still see the lines of the tableView, How can i get to display the custom uiview without seeing the tableView lines on the background.
#implementation LoadingView
#synthesize spinner;
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
[self setUserInteractionEnabled:NO];
[self setBackgroundColor:[UIColor blueColor]];
// Spinner
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setCenter:CGPointMake(320/2, 150)];
[self addSubview:spinner];
[spinner startAnimating];
//title label
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = #"Loading...";
titleLabel.font = [UIFont boldSystemFontOfSize:18];
titleLabel.lineBreakMode = UILineBreakModeWordWrap;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textColor = [UIColor blackColor];
titleLabel.textAlignment = UITextAlignmentLeft;
CGFloat height = [titleLabel.text sizeWithFont: titleLabel.font constrainedToSize: CGSizeMake(300, 1500) lineBreakMode: UILineBreakModeWordWrap].height;
[titleLabel setFrame: CGRectMake(120, 180, 100, height)];
[self addSubview:titleLabel];
[titleLabel release];
}
return self;
}
- (void)drawRect:(CGRect)rect {
}
- (void)dealloc {
[super dealloc];
[spinner release];
}
#end
You can set the lines "off", when you start you loading process, setting them transparent.
// Setting transparent
tableView.separatorColor = [UIColor clearColor];
And when you remove the loading UIView, you change the color for the one that you want.
// Setting the desired color
tableView.separatorColor = [UIColor grayColor];
Another alternative is to set the table view hidden while you don't have data to be displayed, and than when the first or more row appear you place you set the table view to not hidden.
I hope this will help you!
Cheers,
VFN
The problem was that self.view in the viewController had the tableView assigned directly. The solution is to assign the self.view a UIView and add the tableView and the custom UIView on top of self.view.
This is sample code from the viewController.
- (void)loadView {
UIView *aView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//tableView
self.tableView = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain] autorelease];
//set the rowHeight once for performance reasons.
//self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = 75;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.autoresizesSubviews = YES;
[aView addSubview:tableView];
//set the rowHeight once for performance reasons.
self.view = aView;
[aView release];
}
- (void)viewDidLoad {
[super viewDidLoad];
loadingView = [[LoadingView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.view addSubview:loadingView];
//fetch productsArray
[self productListRequestStart];
}