Wait cursor in an iPhone app - iphone

Is there an easy way to display a wait animation in the iPhone sdk. I have a screen that will take a few seconds to load, and I'd like to give the user some feedback that something is happening. Any suggestions?

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
or
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
will do the trick!
edit: Found this one in an older project, client requested an indicator with better visibility:
-(void)invokeMegaAnnoyingPopup
{
self.megaAlert = [[[UIAlertView alloc] initWithTitle:#"Please wait..."
message:nil delegate:self cancelButtonTitle:nil
otherButtonTitles: nil] autorelease];
[self.megaAlert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(self.megaAlert.bounds.size.width / 2,
self.megaAlert.bounds.size.height - 45);
[indicator startAnimating];
[self.megaAlert addSubview:indicator];
[indicator release];
}
-(void)dismissMegaAnnoyingPopup
{
[self.megaAlert dismissWithClickedButtonIndex:0 animated:YES];
self.megaAlert = nil;
}
You would of course need a UIAlertView *megaAlert; defined in your class.

Related

Setting UIActivityIndicator while shifting to another UIview

I need to display activityindicator in didSelectRowatIndexPath event when iam moving from one UIView to another UiView.It should be displayed as long as the process for loading another uiview takes.
How can I do this?
Try below code but I am giving example you should modify it & use according to your need:
alert= [[UIAlertView alloc] initWithTitle:#"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];
Ok after pushing your class use this line to dismiss indicator:
[alert dismissWithClickedButtonIndex:0 animated:YES];
Try. Best of luck.

Viewing Activity Indicator in fullscreen

I am trying to display an activity indicator in full screen so the user cannot press any button in the screen till the activity indicator is turned off as the alert view process. I have called the [activityView startAnimating] but I can push the buttons in the back. Is there way to prevent that?
Thanks from now.
You can use MBProgressHUD for such loading indictators. It's a great MIT-licensed class that extends well if you want to customize it further.
you can try this
UIAlertView *alert= [[[UIAlertView alloc] initWithTitle:#"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
and add this line where you want remove your alert
[alert dismissWithClickedButtonIndex:0 animated:YES];
I'll suggest a best way will be displaying an alertView with activity indicator on the screen.
You can use the following code for this:
declare property for UIAlertView like:
#property (nonatomic, strong) UIAlertView *sendAlert;
self.sendAlert = [[UIAlertView alloc] initWithTitle:#"Loading" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act setFrame:CGRectMake(115, 60, 50, 50)];
[act startAnimating];
[sendAlert addSubview:act];
act = nil;
[sendAlert show];
When you want to remove alert you can use:
[sendAlert dismissWithClickedButtonIndex:0 animated:YES];
sendAlert = nil;
Another alternative, you can add the activity indicator to your view itself and set the userInteraction of backbutton to false. When you finish the task set to True. But It won't be a nice way.
hey for your this requirement use the bellow code which you can access in your every view use..
add this bellow code and object in AppDelegate.h file like bellow..
UIView *activityView;
UIView *loadingView;
UILabel *lblLoad;
and paste this bellow code in AppDelegate.m file
#pragma mark - Loading View
-(void) showLoadingView {
//NSLog(#"show loading view called");
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 60.0, 320.0, 420.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor darkGrayColor];
loadingView.alpha = 0.5;
UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 190.0,150.0 ,50.0)];
subloadview.backgroundColor=[UIColor blackColor];
subloadview.opaque=NO;
subloadview.alpha=0.8;
subloadview.layer.masksToBounds = YES;
subloadview.layer.cornerRadius = 6.0;
lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
lblLoad.text=#"LoadingView";
lblLoad.backgroundColor=[UIColor clearColor];
lblLoad.textColor=[UIColor whiteColor];
[subloadview addSubview:lblLoad];
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[subloadview addSubview:spinningWheel];
[loadingView addSubview:subloadview];
[spinningWheel release];
}
[self.window addSubview:loadingView];
//[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}
-(void) hideLoadingView {
if (loadingView) {
[loadingView removeFromSuperview];
[loadingView release];
loadingView = nil;
}
}
and call this method when you want in any class , just like bellow..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate showLoadingView];
Add a UIView above your current view when activity indicator starts :
UIView *overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.navigationController.view addSubview:overlayView];

I want to display UIProgressView on UIAlertView

I want to display UIProgressView on UIAlertView for displaying the processing of uploading of the file. But I have searched too much and also find on that link but sill unable to do that. I don't get idea from this
If anyone know the easiest way to do that then please let me know.
I've had problems doing this, and ended up with this:
av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];
[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[av setValue:progressView forKey:#"accessoryView"];
[av show];
Try this code...
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
pv.frame = CGRectMake(20, 20, 200, 15);
pv.progress = 0.5;
[av addSubview:pv];
[av show];
While this doesn't quite answer your question, try MBProgressHud, a third-party control that has this feature built-in. The examples supplied on Github should get you up to speed pretty quickly.
Try this code. Put YES for activity indicator and NO for progressView
- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
progressAlert = [[UIAlertView alloc] initWithTitle: message
message: #"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
// Create the progress bar and add it to the alert
if (activity) {
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
[progressAlert addSubview:activityView];
[activityView startAnimating];
} else {
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[progressAlert addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
}
[progressAlert show];
[progressAlert release];
}
Why not make use of the alerviewdelegate method
- (void)willPresentAlertView:(UIAlertView *)alertView
The advantage of this is we can see what size the alertview will actually be on screen, as iOS has precomputed this at this point, so no need for magic numbers - or overriding the class which Apple warn against !
And as of iOS7 I remember reading some document from Apple saying not to hard code any frame sizes but to always compute them from the app, or something along those lines ?
- (void)willPresentAlertView:(UIAlertView *)alertView
{
CGRect alertRect = alertview.bounds;
UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT);
// Do what ever you want here to set up the alertview, as you have all the details you need
// Note the status Bar will always be there, haven't found a way of hiding it yet
// Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h>
objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview
}
To pull reference to the loading bar in
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Then use
UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey);
Remember to have defined
#import <objc/runtime.h>
static char myKey;
At the top of your class declaration
This is create a alert view
UIAlertController* alert=[UIAlertController alertControllerWithTitle:#"Message" message:#"This is test" preferredStyle:UIAlertControllerStyleAlert];
now add textfield
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder=#"Enter Text label";
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.backgroundColor=[UIColor whiteColor];
}];
and added it on view
[self presentViewController:alert animated:YES completion:nil];

TWTweetComposeViewController a strange indentation on top

When you call the following twitter method I always get a strange indentation on top.
Here is my method:
- (void)twitter {
if ([TWRequest class]) {
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:titleDetail];
[twitter addImage:imgPreview];
[twitter addURL:[NSURL URLWithString:linkPost]];
[self presentViewController:twitter animated:YES completion:nil];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
if (res == TWTweetComposeViewControllerResultDone) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Выполнено" message:#"Ваш твит успешно опубликован" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
} else if (res == TWTweetComposeViewControllerResultCancelled) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Ошибка" message:#"Ваш твит неопубликован" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
[self dismissModalViewControllerAnimated:YES];
};
}
}
How do I fix this?
Update: FIXED
The problem was this:
When the application loads (which displays a splash screen) I hide the status bar.
The status bar is initially hidden.
And then, in AppDelegate.m:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[UIApplication sharedApplication].keyWindow.frame = CGRectMake(0, 20, 320, 460);
The problem was precisely in 20:
CGRectMake (0, 20, 320, 460);
The problem was this: When load application (which displays splash screen) I hid status bar.
Status bar is initially hidden YES
And then, in AppDelegate.m:
[[UIApplication sharedApplication] setStatusBarHidden: NO withAnimation: NO];
[UIApplication sharedApplication]. KeyWindow.frame = CGRectMake (0, 20, 320, 460);
The problem was precisely in 20:
CGRectMake (0, 20, 320, 460);

iphone-UIAlertview-UIIndicatorview

i Am New In Iphone development. i have one form in which for display data I am calling a webservice. When that service is called it parses from other file, And Page Navigates To 'Send Page' In Which These Data Is Displayed In a UITableview.
i am also using uiAtertview And UIIndicatorview Both For Displaying that the process is going. But Problem Is When I Click On Button I Call UIAtertView + UIIndicator But It Is Not getting Displayed And Data is Also Not getting Displayed,,,
My Code Is
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Configuring Preferences\nPlease Wait.." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil,nil];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
self.ResultPage = [[ResultPage alloc] init];
self.title=#" Search ";
// Here My Webservice Is Call From Another ViewController Class And That Class Display Data //InTo UITableVIew
[self.ResultPage GetSearchResult:StrBookId : txtFPrice.text :txtTprice.text];
[alert dismissWithClickedButtonIndex:0 animated:YES];
[self.navigationController pushViewController: _ResultPage animated:YES];
Please Suggest Me....
Thanx
You can add activity indicator in alert view and show that alert view when you call web service.I also do the same when I call webservice. it locks the view so that the user cannot click anything and look wise also seems to be fine and indicating user that something is going in process.
in .h file
UIAlertView *progressAlert;
in .m file
-(void)showAlertMethod
{
NSAutoreleasePool *pool1=[[NSAutoreleasePool alloc]init];
progressAlert = [[UIAlertView alloc] initWithTitle:#"Uploading please wait...\n" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
CGRect alertFrame = progressAlert.frame;
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.frame = CGRectMake(135,alertFrame.size.height+55, alertFrame.size.width,30);
activityIndicator.hidden = NO;
activityIndicator.contentMode = UIViewContentModeCenter;
[activityIndicator startAnimating];
[progressAlert addSubview:activityIndicator];
[activityIndicator release];
[progressAlert show];
[pool1 release];
}
-(void)dismissAlertMethod
{
NSAutoreleasePool *pool2=[[NSAutoreleasePool alloc]init];
[progressAlert dismissWithClickedButtonIndex:0 animated:YES];
[pool2 release];
}
call the method according to your requirements.
I call the methods in this way:-
[NSThread detachNewThreadSelector:#selector(showAlertMethod) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:#selector(dismissAlertMethod) toTarget:self withObject:nil];