UIAlertView / Message box in IOS / Objective C

UIAlertView / Message box in IOS / Objective C

Today I am going to explain you how to show a message box or UIAlertView from iphone/ipad application. I have attached a sample scree shot below and the source code below.


If we going show this to mobile user you have to use below code.

UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Your title here!\n"
                                                             message:@"\n\n "
                                                            delegate:self
                                                   cancelButtonTitle:@"Cancel"
                                                   otherButtonTitles:@"OK", nil];
            dialog.tag = 1;
            dialog.alertViewStyle = UIAlertViewStylePlainTextInput;
            [dialog show];

Below I am explaing the code line by line.
----------------------

UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Your title here!\n"
                                                             message:@"\n\n "
                                                            delegate:self
                                                   cancelButtonTitle:@"Cancel"
                                                   otherButtonTitles:@"OK", nil];

Above line is set up the message title , cancel button and OK button titles.
----------------------

dialog.tag = 1;

This line will be help full when we have multiple UIAlertViews. Because app need to identify which alertview has been excuted and I have added it another post titled "Mutiple UIAlertView handling in IOS / Objective C"

---------------------
dialog.alertViewStyle = UIAlertViewStylePlainTextInput;

This line process the title text box of the alertview.
---------------------

 [dialog show];

This shows the UIAlertView to user.

----------------------
Thank you and do not hesitate to contact me if any issues.

Dasun

Comments

Popular Posts