How to get the alert message?

时间:2021-12-09 19:59:02

I have this code and actually i want an alert message when user Tap the delete message ?? how can i do that ..

我有这个代码,实际上我想要一个警告消息,当用户点击删除消息??我怎样才能做到这一点 ..

#pragma mark -
#pragma mark Table Data Source Methods

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return [list count];

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  static NSString *DeleteMeCellIdentifier = @"DeleteMeCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier];
    if (cell==nil) {

        cell =  [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DeleteMeCellIdentifier];
                    }

    NSInteger row = [indexPath row];
    cell.textLabel.text = [self.list objectAtIndex:row];
    return cell;

   }

#pragma mark -
#pragma mark Table View Data Source Methods

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    NSUInteger row = [indexPath row];
    [self.list removeObjectAtIndex:row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];


}

2 个解决方案

#1


3  

Please try this code:

请尝试以下代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

 if (editingStyle == UITableViewCellEditingStyleDelete){
     UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:[NSString 
     stringWithFormat:@"deleted row no. %@",indexPath.row]  delegate:nil 
     cancelButtonTitle:@"Ok" otherButtonTitles: nil];
     [alert show];
     [alert release];
 }
}

#2


0  

You can try this:

你可以试试这个:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger row = [indexPath row];
    [self.list removeObjectAtIndex:row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:[NSString stringWithFormat:@"You have deleted row no. %@",indexPath.row]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];


}

#1


3  

Please try this code:

请尝试以下代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

 if (editingStyle == UITableViewCellEditingStyleDelete){
     UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:[NSString 
     stringWithFormat:@"deleted row no. %@",indexPath.row]  delegate:nil 
     cancelButtonTitle:@"Ok" otherButtonTitles: nil];
     [alert show];
     [alert release];
 }
}

#2


0  

You can try this:

你可以试试这个:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger row = [indexPath row];
    [self.list removeObjectAtIndex:row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:[NSString stringWithFormat:@"You have deleted row no. %@",indexPath.row]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];


}