iOS上导航控制器上带有删除操作表的按钮

iOS上导航控制器上带有删除操作表的按钮,ios,iphone,cocoa,ipad,Ios,Iphone,Cocoa,Ipad,iOS: 我有一个应用程序可以打开一些内容,我在右边的导航栏上添加了一个按钮,可以从保存的捕获中删除消息内容,现在我想在删除消息之前添加符合用户要求的确认操作, 我创建的UIActionsheet如下所示: sheet = [[UIActionSheet alloc] initWithTitle:@"Delete Message" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Message

iOS: 我有一个应用程序可以打开一些内容,我在右边的导航栏上添加了一个按钮,可以从保存的捕获中删除消息内容,现在我想在删除消息之前添加符合用户要求的确认操作, 我创建的UIActionsheet如下所示:

sheet = [[UIActionSheet alloc] initWithTitle:@"Delete Message" delegate:self cancelButtonTitle:@"Cancel"   destructiveButtonTitle:@"Delete Message" otherButtonTitles:nil];
 // view sheet 
 [sheet showInView:self.view];
 NSLog(@"Button %d", buttonIndex);
-(void)popUp
{

    sheet = [[UIActionSheet alloc] initWithTitle:@"Are you Sure?"
                                        delegate:self
                               cancelButtonTitle:@"Cancel"
                          destructiveButtonTitle:@"Delete Message"
                               otherButtonTitles:nil];
    // Show the sheet
    [sheet showInView:self.view];
    //[sheet release];
    NSLog(@"Button %d", buttonIndex);
}
   - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {  //delete it

            //delete from database
            //delete from folder
            [[NSFileManager defaultManager] removeItemAtPath:fileName error:&e];
            //close
            [[self navigationController] popViewControllerAnimated: YES];
        }else if {
             NSLOG(@"USER said No");
        }

    }
现在我如何在deleteContent函数中使用这个值? 我的删除功能是

-(void) deleteContent 
{
   if (buttonIndex=0)
     {
      [[NSFileManager defaultManager] removeItemAtPath:fileName error:&e];
     }
}

我的问题是,我如何在一个函数中重新安排它,而这个函数可以在一次调用中调用并完成所有这一切。

这不是解决问题的方法。从导航栏中的按钮调用函数以显示操作表。然后实现UIActionSheetDelegate方法ActionSheetDidDismissWithButtonIndex以获取实际删除的car


编辑:如果您需要从导致显示操作表的方法中传递要删除的项目的标识,只需向presentActionSheet方法添加一个参数并传递该项目。

有相同问题的人:

为按钮创建一个函数,可以调用如下弹出窗口:

sheet = [[UIActionSheet alloc] initWithTitle:@"Delete Message" delegate:self cancelButtonTitle:@"Cancel"   destructiveButtonTitle:@"Delete Message" otherButtonTitles:nil];
 // view sheet 
 [sheet showInView:self.view];
 NSLog(@"Button %d", buttonIndex);
-(void)popUp
{

    sheet = [[UIActionSheet alloc] initWithTitle:@"Are you Sure?"
                                        delegate:self
                               cancelButtonTitle:@"Cancel"
                          destructiveButtonTitle:@"Delete Message"
                               otherButtonTitles:nil];
    // Show the sheet
    [sheet showInView:self.view];
    //[sheet release];
    NSLog(@"Button %d", buttonIndex);
}
   - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {  //delete it

            //delete from database
            //delete from folder
            [[NSFileManager defaultManager] removeItemAtPath:fileName error:&e];
            //close
            [[self navigationController] popViewControllerAnimated: YES];
        }else if {
             NSLOG(@"USER said No");
        }

    }
然后再创建一个函数,根据如下弹出操作处理删除零件:

sheet = [[UIActionSheet alloc] initWithTitle:@"Delete Message" delegate:self cancelButtonTitle:@"Cancel"   destructiveButtonTitle:@"Delete Message" otherButtonTitles:nil];
 // view sheet 
 [sheet showInView:self.view];
 NSLog(@"Button %d", buttonIndex);
-(void)popUp
{

    sheet = [[UIActionSheet alloc] initWithTitle:@"Are you Sure?"
                                        delegate:self
                               cancelButtonTitle:@"Cancel"
                          destructiveButtonTitle:@"Delete Message"
                               otherButtonTitles:nil];
    // Show the sheet
    [sheet showInView:self.view];
    //[sheet release];
    NSLog(@"Button %d", buttonIndex);
}
   - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {  //delete it

            //delete from database
            //delete from folder
            [[NSFileManager defaultManager] removeItemAtPath:fileName error:&e];
            //close
            [[self navigationController] popViewControllerAnimated: YES];
        }else if {
             NSLOG(@"USER said No");
        }

    }

酷。如果我的回答有帮助,请在旁边打勾:)