show alert while deleting a uitableViewCell ios5
I am implementing a swipe to delete functionality in uitableview. I am able to achieve that, but now i wish to display a alert message to confirm delete. I have created the tableview programmatically.
Here's my code.

    ViewController.h
    @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
    
    UITableView *tView;
    NSMutableArray *myArray;
    NSIndexPath *lastIndexPath;
    }

    @property(nonatomic,retain) UITableView *tView;
    @property(nonatomic,retain) NSMutableArray *myArray;
    @property(nonatomic,retain) NSIndexPath *lastIndexPath;
    @end

    ViewController.m
    - (void)viewDidLoad
    {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor lightGrayColor];
    
    myArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
    
	// Do any additional setup after loading the view, typically from a nib.
    tView = [[UITableView alloc] initWithFrame:CGRectMake(30, 30, 700, 800) style:UITableViewStylePlain];
    tView.delegate=self;
    tView.dataSource=self;
    [self.view addSubview:tView];
    [tView release];
    }


    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return 100.0;
    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return [myArray count];
    }

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
    }

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Delete" message:@"Are you sure?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];

    [alert show];
    [alert release];
           if (editingStyle == UITableViewCellEditingStyleDelete) {
               lastIndexPath = indexPath;
               NSLog(@"%@......%d",lastIndexPath,lastIndexPath.row);
    }
    }

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    if(buttonIndex==0)
    {
        
        NSLog(@"cancel");
    }
    else {
        NSLog(@"delete");
        [myArray removeObjectAtIndex:lastIndexPath.row];    //memory error 
        [tView deleteRowsAtIndexPaths:[NSArray arrayWithObject:lastIndexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {//..do required thing and return cell}


I get a memory error in the clickButtonAtIndex method for alert view. I think it is for the lastIndexPath, but the nslog() give the correct value in lastIndexPath.
What am i doing wrong?
 
show alert while deleting a uitableViewCell ios5
===

I am implementing a swipe to delete functionality in uitableview. I am able to achieve that, but now i wish to display a alert message to confirm delete. I have created the tableview programmatically.
Here's my code.

    ViewController.h
    @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
    
    UITableView *tView;
    NSMutableArray *myArray;
    NSIndexPath *lastIndexPath;
    }

    @property(nonatomic,retain) UITableView *tView;
    @property(nonatomic,retain) NSMutableArray *myArray;
    @property(nonatomic,retain) NSIndexPath *lastIndexPath;
    @end

    ViewController.m
    - (void)viewDidLoad
    {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor lightGrayColor];
    
    myArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
    
	// Do any additional setup after loading the view, typically from a nib.
    tView = [[UITableView alloc] initWithFrame:CGRectMake(30, 30, 700, 800) style:UITableViewStylePlain];
    tView.delegate=self;
    tView.dataSource=self;
    [self.view addSubview:tView];
    [tView release];
    }


    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return 100.0;
    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return [myArray count];
    }

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
    }

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Delete" message:@"Are you sure?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];

    [alert show];
    [alert release];
           if (editingStyle == UITableViewCellEditingStyleDelete) {
               lastIndexPath = indexPath;
               NSLog(@"%@......%d",lastIndexPath,lastIndexPath.row);
    }
    }

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    if(buttonIndex==0)
    {
        
        NSLog(@"cancel");
    }
    else {
        NSLog(@"delete");
        [myArray removeObjectAtIndex:lastIndexPath.row];    //memory error 
        [tView deleteRowsAtIndexPaths:[NSArray arrayWithObject:lastIndexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {//..do required thing and return cell}


I get a memory error in the clickButtonAtIndex method for alert view. I think it is for the lastIndexPath, but the nslog() give the correct value in lastIndexPath.
What am i doing wrong?
 