I want to create a UIAlertView that will say that "...in progress". It will also show that UIActivityindicatorView on it. Could you let me know how can I do that?
Thanks.
Its pretty simple. Just create a UIActivityIndicatorView and add it as a subview to the UIAlertView.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#" " message:#" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[progress startAnimating];
[alert show];
In my case i found what using hardcoded frame origins it's bad. And if my message has more one line, indicator showing top of my message.
So i create function with layouting indicator if size UIAlertView
+(UIAlertView*) progressAlertWithTitle:(NSString*) title andMessage:(NSString*) message andDelegate:(id)delegate{
UIAlertView *progressAlert = [[UIAlertView alloc] init];
[progressAlert setTitle:title];
[progressAlert setMessage:message];
[progressAlert setDelegate:delegate];
UIActivityIndicatorView *progress=nil;
progress= [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[progressAlert addSubview:progress];
[progress startAnimating];
[progressAlert show];
progress.frame=CGRectMake(progressAlert.frame.size.width/2-progress.frame.size.width, progressAlert.frame.size.height-progress.frame.size.height*2, progress.frame.size.width, progress.frame.size.height);
return progressAlert;
}
In this case, indicator always by center
One line message:
More one line message:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGRectMake(xcords, ycords, width, height);
[alert addSubview:spinner];
[spinner startanimating];
[alert show];
This spinner gets hidden on dismiss of AlertView.
[alert dismissWithClickedButtonIndex:0 animated:YES];
Related
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.
I want to display a activity indicator in AlertView with no buttons, I want to disable it when activity indicator stops animating.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[progress startAnimating];
[alert show];
[progress release];
Then to dismiss the alert view and spinner: (you'll need to make the alert view a member)
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
Just call dismissWithClickedButtonIndex:animated: method for UIAlertView
[alertView dismissWithClickedButtonIndex:0 animated:YES];
Just call the:
[theAlertViewInstance dismissWithClickedButtonIndex: 0 animated:YES];
This should do, what you need.
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];
I want to add an activity Indicator View inside and Alert Box is it possible to add an subView inside Another subView?
Use below code :
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#" " message:#" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *myActivityIndicatorView= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 60, 40, 40)];
myActivityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[myAlert addSubview:myActivityIndicatorView];
[myActivityIndicatorView startAnimating];
[myAlert show];
yes it is possible...
[alertView addSubview:activityIndicator];
Technically, yes.
Simply alloc and init both views, then call
[alertView addSubview:activityView];
However, if this passes Apple's inspection is doubtful, so you may not be able to publish to the AppStore.
I want to display an alert view with a search bar option on it. How can I create a search bar in a alert view? Any sample codes would be helpful.
I have created a search bar and and added the text box as its subview.
UIAlertView * myAlertView = [[UIAlertView alloc] initWithTitle:#" "
message:#" "
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil, nil];
UISearchBar *myTextField = [[UISearchBar alloc] initWithFrame:CGRectMake(30.0, 35.0, 180.0, 35.0)];
UIButton *searchbtn = [[UIButton alloc] initWithFrame:CGRectMake(230.0, 35.0, 40.0, 35.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView setBackgroundColor:[UIColor grayColor]];
[searchbtn setBackgroundColor:[UIColor grayColor]];
[myAlertView addSubview:myTextField];
[myAlertView addSubview:searchbtn];
If there is any other better way please let me know.
There is a better way:
UIAlertView *myAlertView = [[[UIAlertView alloc] initWithTitle:#"Keyword Search"
message:#""
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Search", nil] autorelease];
myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[myAlertView show];
And in the Delegate:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSString *searchTerm = [alertView textFieldAtIndex:0].text;
}