Alert me, please

Some important things that you must do in iOS it’s to show a message in the middle of the screen. A popup, expert will say. Here’s a small code to do it.

- (void)SacaAlerta {
    // First, we create an object called alert part of the UIAlertView
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Text of the alert"
                                                    message:nil
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert autorelease];
    [alert show];
}

Ok, you will not have the same as the image, but if you read the code it’s easy to put more buttons (otherButtonTitles) or messages in it (message). In this example there are equal to nil (or Null for friends).

Of course, you are enough smart to know that this function doesn’t return anything (void) and how you can use it 🙂

Comment