【问题标题】:how to use uialert and uiactionsheet in tableview如何在 tableview 中使用 uialert 和 uiactionsheet
【发布时间】:2012-08-21 06:51:20
【问题描述】:

我有一个项目的表格视图,当我单击一行时,我想将 uialertview 与带有按钮的 uiactionsheet 一起使用:编辑、删除和取消。当我单击按钮编辑时,我将打开一个模式视图。之前,我已经编辑了模态视图,当我点击一行时,我会去编辑模态视图,但是现在我想添加 uiactionsheet,那么我该怎么做呢?

【问题讨论】:

    标签: iphone ios uialertview uiactionsheet


    【解决方案1】:

    -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 方法中写入 UIAlertview 或 UIActionsheet。

    我认为这对你会有帮助。

    -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"delete" otherButtonTitles:@"other 1", @"other 2", nil];
    [actionSheet showInView:self.view];
    
    //or
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"button",@"button1", nil];
        [alert show];
    
    }
    

    【讨论】:

      【解决方案2】:

      只需按如下方式使用 UIAlertView:

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Edit", @"Remove", nil];
      [alert show];
      

      以下方法将检查按下的是哪个按钮:

      - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
      {
          switch (buttonIndex)
          {
               case 1:
               // perform Edit
                   break;
               case 2:
               // perform Remove
                   break;
               case 0:
               // perform Cancel, if any
                   break;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-05
        • 2015-02-22
        • 1970-01-01
        • 1970-01-01
        • 2013-07-06
        相关资源
        最近更新 更多