views:

307

answers:

2

I'd like to display a temporary message on the iPhone/iPad displaying confirmation of an action, or some quick status about some background activity.

Is there a standard control to do this? I've seen apps do this. A rounded rectangle, dark and partially transparent with text inside. It does not ask for user input but disappears on its own in some short period of time. Android has a similar construct which is standard. Also similar to the windows displayed by Growl.

Suggestions appreciated.

+1  A: 

Use UIAlertView. Here's a quick link to a simple example:

UIAlertView

Edited: Sorry, didn't see about disappearing on it's own. I think you need to have some confirmation by users of messages received. UIAlertView pretty much accomplishes that. Not sure if you have it gradually fade away unless you're in an app with a view that has a timer or event based delay that will show a view and then eventually remove it.

Second edit: Found a way to implement it. You can manually call the dismiss function after some set time that you've designated. (Sorry for the messy post) It would look something like this:

//Create UIAlertView alert
alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Some message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];

//After some time
[alert dismissWithClickedButtonIndex:0 animated:TRUE];
Kennzo
I've implemented something quick and dirty using a UIAlertView with no buttons. I dismiss it myself after a delay. It works, but does not look anywhere near as good as what I described. If its not built into the platform, there must be an implementation somewhere. Doesn't seem too hard to implement on your own, but seems that someone should have already done it. The app 'FeeddlerRSS' uses something like it constantly.
David
I found a post for another similar question. I think this is more what you're talking about: http://stackoverflow.com/questions/593147/how-to-display-a-progress-indicator-overlay-hud-on-iphone
Kennzo
A: 

Create a class that inherits from UIAlertView. In your constructor just call [super init] and then add any view you want as a subview. You can even design this view in Interface Builder. Something like this:

- (id)initWithMessage:(NSString *)message dismissAfter:(NSTimeInterval)interval
{
  if ((self = [super init]))
  {
     CustomView * customView = [[[CustomView alloc] init] autorelease]; // or load from NIB
     [self addSubView:customView];
     [self performSelector:@selector(dismissAfterDelay) withObject:nil afterDelay:interval];
  }
  return self;
}

- (void)dismissAfterDelay
{
  [self dismissWithClickedButtonIndex:0 animated:YES]; 
}

To display your custom alert view just init it, and call show as with a regular UIAlertView.

CustomAlertView * cav = [[CustomAlertView alloc] initWithMessage:@"Doing Something];
[cav show];
[cav release];

As an nice side-effect, when you present this view the background will darken and you will get the nice wobbly animation for any alert view.

Marco Mustapic