views:

103

answers:

2

I was just curious about how can i attach some different task to the otherButtonTitle of UIAlertView. The cancel button automatically take you out of the application but if i want to attach a different task with the otherButtonTitle ,what should i do?

Thanks,

A: 

UIAlertView delegate "didDismissWithButtonIndex" get called every time u click any button.

Try this:

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" 
                                                message:messageString
                                               delegate:self 
                                      cancelButtonTitle:@"Back"
                                      otherButtonTitles:@"Reply",@"Delete",nil];
[alert show];
[alert release];



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

  if (buttonIndex == 1){
    NSLog(@"Reply");
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Reply " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [myalert show];
    [myalert release];

}
if (buttonIndex == 2){
    NSLog(@"Delete");
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Delete " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [myalert show];
    [myalert release];

}
iPhoneDev
Its not dong anything when i click any of those buttons.
Ashutosh
find updated code
iPhoneDev
A: 

Here's my code but when i am clicking on any button it just giving me a white screen.

import "Hello_WorldAppDelegate.h"

@implementation Hello_WorldAppDelegate

@synthesize window;

  • (void)applicationDidFinishLaunching:(UIApplication *)application {

    // Override point for customization after application launch UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Welcome to my Alert View" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Reply", @"Delete", nil];

    [myalert show]; [myalert release];

    [window makeKeyAndVisible];

}

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

if (buttonIndex == 1){

NSLog(@"Reply");

}

if (buttonIndex == 2){

NSLog(@"Delete");

}

}

  • (void)dealloc { [window release]; [super dealloc]; }
Ashutosh
Please find the edit code... try this, it should work.(Mark it as answer if your query is resolved) thanks
iPhoneDev
It worked.... Thanks!!!!
Ashutosh
Please mark it answer and close this thread.
iPhoneDev