Asad Ullah
Asad Ullah

Reputation: 117

How to add a confirming pop up window in objective?

like JOptionPane in java, when user do something. and i ask for confirmation like, are you sure you want to delete file?? or whatever the case is. user confirms it then i detect what user has chosen between both buttons then i do something according to user choice

is there anything like this in objective c ?? links plz and some guidelines

thank you every one

Upvotes: 0

Views: 467

Answers (3)

Imirak
Imirak

Reputation: 1333

What you want to do is check which button is being clicked under otherButtonTitles:

Something like this:

UIAlertView *yourAlert = [[UIAlertView alloc] initWithTitle:@"Your title" message:@"Some String" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Confirm",nil];  

 [yourAlert show];

And remember to set the delegate to self.

Then:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {

if (buttonIndex == 0){

    //'Dismissing' code here

}

if (buttonIndex == 1){

    //Detecting whatever was under otherButtonTitles:
    //Right now it's checking if the user clicked "Confirm" -> So here you can put whatever you need
   NSLog(@"You clicked Confirm");

      }

}

Under the conditionals, you are checking which button the user is clicking.

Upvotes: 0

Richard J. Ross III
Richard J. Ross III

Reputation: 55563

I believe that you want UIActionSheet, which is what Apple Recommends for user choice:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Some Message" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"button To Destroy or nil" otherButtonTitles:@"Choice 1", @"Choice 2", @"Choice 3", nil];

Upvotes: 0

OthmanT
OthmanT

Reputation: 223

You are looking for UIAlertView controller.

Upvotes: 2

Related Questions