Is it possible to create an UIAlertView without any buttons? - objective-c

I need help with UIAlertView :-). Currently I have an UIAlertView showing up when the user shakes the device using the -(void)motionEnded: function. I want to make the alert view disappear after 0.5 seconds using a NSTimer so I don't need any button at the bottom of the alert view to dismiss it. Is there a way to create an UIAlertView without any button? [A way to remove the space with the arrow in the image below?]
Here's the code:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
resetAlert = [[UIAlertView alloc] initWithTitle:#"Reset!"
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil, nil];
[resetAlert show];
alertHideTimer = [NSTimer scheduledTimerWithTimeInterval:10.5 target:self selector:#selector(dismissWithClickedButtonIndex:animated:) userInfo:nil repeats:NO];
self.label.text = #"0";
numero = 0;
[self.label2 setHidden:YES];
}

Yes it is. Try the following: iToast

You can create your own view. Show and hide/close it as per your requirement, timers etc.

I'm not sure if having the NSTimer with a multiple argument selector is correct. I add this method:
-(void)dismissAlertView:(UIAlertView*)alertView {
[alertView dismissWithClickedButtonIndex:0 animated:NO];
}
and replace your NSTimer with:
[self performSelector:#selector(dismissAlertView:) withObject:resetAlert afterDelay:0.5];

As far as I know removing the space entirely is not possible.
However... here are some things you may want to try;
Adding top padding
Add a few newlines to get top padding: initWithTitle:#"\n\nConfiguring Preferences...
(source: iosdevelopertips.com)
Adding a spinner
Add a UIActivityIndicatorView to the UIAlertView
alert = [[UIAlertView alloc] initWithTitle:#"Configuring Preferences\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: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];
(source: iosdevelopertips.com)
Hope that helps.

You can hide the alert simply by calling the delegate method after 5 sec
[alert dismissWithClickedButtonIndex:0 animated:YES];

Related

UIAlertView does not work with UIBarButton

I have a strange problem:
Trying to call an action which contains NSLog and UIAlert using a UIBarButtonItem from a NavigationController. NSLog prints and UIAlert doesn't appear…
-(void)addNewItem
{
UIAlertView *alertAddnewItem = [[UIAlertView alloc]initWithTitle:#"Hello!" message:#"hello!" delegate:self cancelButtonTitle:#"NO" otherButtonTitles:#"YES", nil];
[self.view addSubview:alertAddnewItem];
NSLog(#"Hello!");
}
I guess the problems is with [self.view addSubview:alertAddnewItem];
Thank you!
call:
[alertAddnewItem show];
not
[self.view addSubview:alertAddnewItem];

iOS 7: Change height of UIAlertView

I've gone through several posts explaining how to change alert view height but none of worked for me. Here is the scenario:
I am inserting a custom view inside alert view like this:
MyViewController *myViewController = [self.storyboard instantiateViewControllerWithIdentifier: #"MyView"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alertView setValue: myViewController.view forKey:#"accessoryView"];
[alertView show];
After adding custom view (i.e. myViewController.view), the size of alert view increased unnecessarily. To set desired size to alert view, I implemented following method:
- (void)willPresentAlertView:(UIAlertView *)alertView
{
[alertView setFrame:CGRectMake(0, 0, 280, 300)];
}
Still there was no change in alert view height. Any ideas how can I do that? Please help
Problem solved..!! I just changed the height of sub view. Inside viewDidLoad method of MyViewController I adjusted the size of view.

Code breakpoint

Hi I have a code that when I run quits and says there is a breakpoint
- (void)checkCollision{
if(CGRectIntersectsRect(penny.frame, hand.frame))
{
[randomMain invalidate];
[startButton setHidden:NO];
pos= CGPointMake(0.0, 0.0);
CGRect frame = [penny frame];
frame.origin.x=137.0f;
frame.origin.y=326.0;
[penny setFrame:frame]; (the breakpoint is here)
CGRect frame2 = [hand frame];
frame2.origin.x=137.0f;
frame2.origin.y=20.0;
[hand setFrame:frame2];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"You Lose" message:[NSString stringWithFormat:#"He got the penny!"] delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
any ideas?
i apologize for the sloppy format Im new to the website, thanks!
Sometimes a breakpoint gets out of sync with the code presented. Try going to your breakpoint window (Command + 6 or View->Navigators->Show Breakpoint Navigator.
In that navigator, you may see active breakpoints. If you can find the errant breakpoint, delete it from the list. Otherwise, your best bet is to delete all your breakpoints.

how to make a UIAlertView to hide automatically without User Interaction?

When the focus in a particluar rect of the screen , it need to show up a message and need to hide automatically . Whether alertview will be flexible or any other way is there to implement the stuffs in iPhone and iPad .
You can use timer to close alert after some time, for example:
[[NSTimer scheduledTimerWithTimeInterval:2
target:self
selector:#selector(closeAlert:)
userInfo:nil
repeats:NO] retain];
For more information look here: NSTimer Class Reference
You can dismiss the alert after displaying for some seconds.
Something like this : (Dismiss after 5 seconds)
UIAlertView *yourAlert = [[UIAlertView alloc]initWithTitle:#"title" message:#"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[yourAlert show];
[self performSelector:#selector(dismiss:) yourAlert afterDelay:5.0];
-(void)dismiss:(UIAlertView*)alert
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}

Dismiss actionSheet before action under it's button is completed

My problem is that i have an ActionSheet, which is disappearing from screen only when action under this button is completed. My problem is that i want to click 'save' inside my action sheet, then dismiss action sheet and then to show some alert, informing user to wait until saving is done. Currently it works different: firstly action sheet is shown, then there is saving message UNDER action sheet, finally action sheet is removed from view.. so user doesnt see any alert message.
How to dismiss actionSheet earlier than xcode does it?
Method under sheetActionButton:
- (IBAction)saveAction:(id)sender
{
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:#"Saving photo to library\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[self saveImageToCameraRoll];
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
You should move your saveImageToCameraRoll method onto a separate thread, or at least asynchronously on the main thread. Then you can dismiss the alert and saveAction: can return before it completes.
The simplest way to do this would be using dispatch_async. Use dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) to get a queue for a separate thread, or dispatch_get_main_queue() for the main thread. Make sure not to do any UI work (or use any APIs which aren't thread-safe) on other threads!
Edit: more detail:
- (IBAction)saveAction:(id)sender {
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:#"Saving photo to library\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Save in the background
[self saveImageToCameraRoll];
dispatch_async(dispatch_get_main_queue(), ^{
// Perform UI functions on the main thread!
[alert dismissWithClickedButtonIndex:0 animated:YES];
});
});
}