Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS中显示刷卡删除警报_Ios_Objective C_Uitableview - Fatal编程技术网

在iOS中显示刷卡删除警报

在iOS中显示刷卡删除警报,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我是iOS的初学者。我正在执行滑动删除选项。我想在删除行之前显示警报视图。如何执行此操作 - (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"%@",collisionsArray); if (editingStyle == UIT

我是iOS的初学者。我正在执行滑动删除选项。我想在删除行之前显示警报视图。如何执行此操作

- (void)tableView:(UITableView *)tableView commitEditingStyle:
  (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",collisionsArray);
if (editingStyle == UITableViewCellEditingStyleDelete)
{       
  NSUserDefaults *userinfo = [NSUserDefaults standardUserDefaults];
  NSString *userId = [userinfo valueForKey:@"user_id"];
  if(userId!=nil)
  {
  NSDictionary* dict = [collisionsArray objectAtIndex:indexPath.section];
  collisionId = [NSString stringWithFormat:@"%@",[dict valueForKey:@"collisionId"]];
  NSLog(@"%@",collisionId);
// removes saved datas from database
  BOOL result =  [database removeCollisionDetails:collisionId:@"accident_report"];
    if(result)
    {  
    [[SHKActivityIndicator currentIndicator] 
    displayCompleted:NSLocalizedString(@"val_sucess_vehicle", nil)];
    [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
    [[SHKActivityIndicator currentIndicator]
    displayCompleted:NSLocalizedString(@"val_error", nil)];
    }
  }
}
[self.tableView reloadData];
}

为此,您只需在以下位置显示alet视图:

if (editingStyle == UITableViewCellEditingStyleDelete){
 // Show your alert view
 // Set its delegate to self
}
现在,您必须执行以下操作:

#pragma mark ---- Delegate for alertview ----
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSUserDefaults *userinfo = [NSUserDefaults standardUserDefaults];
    NSString *userId = [userinfo valueForKey:@"user_id"];
    if(userId!=nil)
    {
        NSDictionary* dict = [collisionsArray objectAtIndex:indexPath.section];
        collisionId = [NSString stringWithFormat:@"%@",[dict valueForKey:@"collisionId"]];
        NSLog(@"%@",collisionId);
// removes saved datas from database
            BOOL result =  [database removeCollisionDetails:collisionId:@"accident_report"];
        if(result)
            {  
                [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_sucess_vehicle", nil)];
                [self.navigationController popViewControllerAnimated:YES];
            }



 else
        {
            [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_error", nil)];
        }
        }
    }

为此,您只需在以下位置显示alet视图:

if (editingStyle == UITableViewCellEditingStyleDelete){
 // Show your alert view
 // Set its delegate to self
}
现在,您必须执行以下操作:

#pragma mark ---- Delegate for alertview ----
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSUserDefaults *userinfo = [NSUserDefaults standardUserDefaults];
    NSString *userId = [userinfo valueForKey:@"user_id"];
    if(userId!=nil)
    {
        NSDictionary* dict = [collisionsArray objectAtIndex:indexPath.section];
        collisionId = [NSString stringWithFormat:@"%@",[dict valueForKey:@"collisionId"]];
        NSLog(@"%@",collisionId);
// removes saved datas from database
            BOOL result =  [database removeCollisionDetails:collisionId:@"accident_report"];
        if(result)
            {  
                [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_sucess_vehicle", nil)];
                [self.navigationController popViewControllerAnimated:YES];
            }



 else
        {
            [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_error", nil)];
        }
        }
    }

为此,您只需在以下位置显示alet视图:

if (editingStyle == UITableViewCellEditingStyleDelete){
 // Show your alert view
 // Set its delegate to self
}
现在,您必须执行以下操作:

#pragma mark ---- Delegate for alertview ----
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSUserDefaults *userinfo = [NSUserDefaults standardUserDefaults];
    NSString *userId = [userinfo valueForKey:@"user_id"];
    if(userId!=nil)
    {
        NSDictionary* dict = [collisionsArray objectAtIndex:indexPath.section];
        collisionId = [NSString stringWithFormat:@"%@",[dict valueForKey:@"collisionId"]];
        NSLog(@"%@",collisionId);
// removes saved datas from database
            BOOL result =  [database removeCollisionDetails:collisionId:@"accident_report"];
        if(result)
            {  
                [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_sucess_vehicle", nil)];
                [self.navigationController popViewControllerAnimated:YES];
            }



 else
        {
            [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_error", nil)];
        }
        }
    }

为此,您只需在以下位置显示alet视图:

if (editingStyle == UITableViewCellEditingStyleDelete){
 // Show your alert view
 // Set its delegate to self
}
现在,您必须执行以下操作:

#pragma mark ---- Delegate for alertview ----
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSUserDefaults *userinfo = [NSUserDefaults standardUserDefaults];
    NSString *userId = [userinfo valueForKey:@"user_id"];
    if(userId!=nil)
    {
        NSDictionary* dict = [collisionsArray objectAtIndex:indexPath.section];
        collisionId = [NSString stringWithFormat:@"%@",[dict valueForKey:@"collisionId"]];
        NSLog(@"%@",collisionId);
// removes saved datas from database
            BOOL result =  [database removeCollisionDetails:collisionId:@"accident_report"];
        if(result)
            {  
                [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_sucess_vehicle", nil)];
                [self.navigationController popViewControllerAnimated:YES];
            }



 else
        {
            [[SHKActivityIndicator currentIndicator] displayCompleted:NSLocalizedString(@"val_error", nil)];
        }
        }
    }

使用
UIAlertView
并仅在用户确认后删除。将代码更新为:

if (editingStyle == UITableViewCellEditingStyleDelete)
{       

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello World!"
                                                      message:@"Are you sure ?"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];

[alertView show];
}

执行
UIAlertViewDelegate
并将原始删除代码移动到delegate方法,在该方法中可以检测已点击的按钮。

使用
UIAlertView
,只有在用户确认后才能删除。将代码更新为:

if (editingStyle == UITableViewCellEditingStyleDelete)
{       

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello World!"
                                                      message:@"Are you sure ?"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];

[alertView show];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{


if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warring" message:@"Are You Sure?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes ", nil];


[alert show];



}


}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {


}else if (buttonIndex == 1){
     NSIndexPath *indexPath=[_UserTableView indexPathForSelectedRow];
    [showUData removeObjectAtIndex:indexPath.row]; //showUData NSMutableArray
    [_UserTableView reloadData];
    [storeData setObject:showUData forKey:@"SendData"]; //storeData NSUserDefault
    [storeData synchronize];
}

}

执行
UIAlertViewDelegate
并将原始删除代码移动到delegate方法,在该方法中可以检测已点击的按钮。

使用
UIAlertView
,只有在用户确认后才能删除。将代码更新为:

if (editingStyle == UITableViewCellEditingStyleDelete)
{       

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello World!"
                                                      message:@"Are you sure ?"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];

[alertView show];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{


if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warring" message:@"Are You Sure?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes ", nil];


[alert show];



}


}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {


}else if (buttonIndex == 1){
     NSIndexPath *indexPath=[_UserTableView indexPathForSelectedRow];
    [showUData removeObjectAtIndex:indexPath.row]; //showUData NSMutableArray
    [_UserTableView reloadData];
    [storeData setObject:showUData forKey:@"SendData"]; //storeData NSUserDefault
    [storeData synchronize];
}

}

执行
UIAlertViewDelegate
并将原始删除代码移动到delegate方法,在该方法中可以检测已点击的按钮。

使用
UIAlertView
,只有在用户确认后才能删除。将代码更新为:

if (editingStyle == UITableViewCellEditingStyleDelete)
{       

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello World!"
                                                      message:@"Are you sure ?"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];

[alertView show];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{


if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warring" message:@"Are You Sure?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes ", nil];


[alert show];



}


}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {


}else if (buttonIndex == 1){
     NSIndexPath *indexPath=[_UserTableView indexPathForSelectedRow];
    [showUData removeObjectAtIndex:indexPath.row]; //showUData NSMutableArray
    [_UserTableView reloadData];
    [storeData setObject:showUData forKey:@"SendData"]; //storeData NSUserDefault
    [storeData synchronize];
}

}

执行
UIAlertViewDelegate
并将原始删除代码移动到delegate方法,在该方法中,您可以检测已点击的按钮。

查看@Ashutosh answer代表执行部分查看@Ashutosh answer代表执行部分查看@Ashutosh answer代表执行部分查看@a代表执行部分的自动答案如果问题已解决,请不要忘记勾选答案a s这可能有助于其他用户快速找到解决方案:)如果问题已解决,请不要忘记勾选答案a s这可能有助于其他用户快速找到解决方案:)如果问题已解决,请不要忘记要勾选答案,这可能有助于其他用户快速找到解决方案:)如果问题已解决,请不要忘记勾选答案,这可能有助于其他用户快速找到解决方案:)请考虑稍微解释一下您的代码,以澄清它是如何工作表视图单元格执行删除记录……和单元格显示删除方法的[UITableViewCellEditingStyleDelete]和自动显示删除按钮请考虑稍微解释一下您的代码,以阐明它是如何工作的表视图单元格执行删除记录……和单元格显示删除方法[UITableViewCellEditingStyleDelete]和“自动显示删除”按钮考虑解释一下您的代码,以阐明它是如何工作的表视图单元格执行删除记录……和单元格显示删除方法[UITableViewCellEditingStyleDelete]和自动显示删除按钮考虑解释一下您的代码,以阐明它是如何工作的表视图单元格执行删除记录……以及单元格显示删除方法[UITableViewCellEditingStyleDelete]和自动显示删除按钮
-(void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{


if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warring" message:@"Are You Sure?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes ", nil];


[alert show];



}


}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {


}else if (buttonIndex == 1){
     NSIndexPath *indexPath=[_UserTableView indexPathForSelectedRow];
    [showUData removeObjectAtIndex:indexPath.row]; //showUData NSMutableArray
    [_UserTableView reloadData];
    [storeData setObject:showUData forKey:@"SendData"]; //storeData NSUserDefault
    [storeData synchronize];
}

}