The class UIAletrView allows you to display a modal window (animated) to inform and / or ask you something. The UIAlterView (view alerts) are very comfortable and easy to use. The management of user response is solved by intercepting the index of the button pressed. To view a simple UIAlterView just write:
1 2 3 4 | / / Alert with a simple button, with no callback [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" cancelButtonTitle : @ "Annulla" otherButtonTitles : nil ] ; UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" cancelButtonTitle: @ "Cancel" otherButtonTitles: nil]; ; [MyAlert show]; ; [MyAlert release]; |
And 'possible to add additional buttons otherButtonTitles :
1 2 3 4 | / / Alert with two simple buttons, no callback [ [ UIAlertView UIAlertView MyAlert * = [[UIAlertView ; [MyAlert show]; ; [MyAlert release]; |
: To determine which button was pressed, simply add the delegate:self object initialization UIAlterView :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | / / Simple alert with two buttons and callbacks [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" delegate : self cancelButtonTitle : @ "Annulla" otherButtonTitles : @ "Ok" , nil ] ; UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" delegate: self cancelButtonTitle: @ "Cancel" otherButtonTitles: @ "OK", nil]; ; [MyAlert show]; ; [MyAlert release]; / / The callback looks like this void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex { - (Void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) {buttonIndex buttonIndex ) { switch (buttonIndex) { : case 1: / / Code break; } } |
The callback alertView need to have that name, for more information see UIAlertViewDelegate
punteranno sempre a quella. With only the callbck alertView:clickedButtonAtIndex more UIAletrView will always point to that. Using the tag of the field UIAletrView , we can determine what the "caller":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | / / Simple alert with two buttons and callbacks [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" delegate : self cancelButtonTitle : @ "Annulla" otherButtonTitles : @ "Ok" , nil ] ; UIAlertView MyAlert * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" delegate: self cancelButtonTitle: @ "Cancel" otherButtonTitles: @ "OK", nil]; ; myAlertA.tag = 1; ; [MyAlert show]; ; [MyAlert release]; / / [ [ UIAlertView alloc ] initWithTitle : @ "Titolo" message : @ "Messaggio" delegate : self cancelButtonTitle : @ "Annulla" otherButtonTitles : @ "Ok" , nil ] ; UIAlertView myAlertB * = [[UIAlertView alloc] initWithTitle: @ "Title" message: @ "Message" delegate: self cancelButtonTitle: @ "Cancel" otherButtonTitles: @ "OK", nil]; ; myAlertA.tag = 2; ; [MyAlertB show]; ; [MyAlertB release]; / / Multiple management UIAlertView void ) alertView : ( UIAlertView * ) alertView clickedButtonAtIndex : ( NSInteger ) buttonIndex { - (Void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) {buttonIndex "Alert Tag: %i" , alertView.tag ) ; NSLog (@ "Alert Tags:% i", alertView.tag); "buttonIndex: %i" , buttonIndex ) ; NSLog (@ "buttonIndex:% i", buttonIndex); } |











Hello I have a question ..
I copied your line of code (the last window)
but I get this error:
error: 'alertView' undeclared (first use in this function)error: expected ';' before ':' token
Whi?
@ Corninos: in. H file in your class (I do not know where you entered the code) you must insert the function prototype, namely:
In addition, careful, you could have made a typo somewhere. If necessary incollami your whole code or send me a email.
Hello and thank you for having responded to me in the end I had a typo, or copying.
Within the second
alertViewyou wrote:and so I did not work properly in:
and everything seems to work ..
Now I have made you one more question "stupid" but if I wanted to change the background color of a button or label .. or even just the title of a button as I do? I have tried:
but does not work, then I tried
I thank you in advance!
(dislessia @ Corninos: in fact half my fault: I realized that I had written
I corrected the code in the post). , agendo su
Alterinstead ofAlert(dyslexiacancelButtonTitleeotherButtonTitlesma non puoi alterare lo stile, essendo elementi di sistema. For the titles and the style of the buttons, if you're referring to 'UIAlertView, you can change the labels during the creation of 'UIAlertView, acting oncancelButtonTitleandotherButtonTitlesbut you can not alter the style, being elements of the system.Unless you're referring to a simple button
UIButton... if I understand the question?!@ Giovambattista Fazioli:
I riferifo a generic button ..
UIButtonis an OFF-TOPIC ..@ Corninos: If you're referring to a button
UIButtonthe label is changed as follows:The background, however, you can change it in this way, although it depends on what type of button you are using: