【问题标题】:Can we navigate to a new view when clicking a sub menu inside a Expandable table view?单击可扩展表视图中的子菜单时,我们可以导航到新视图吗?
【发布时间】:2016-10-17 07:07:56
【问题描述】:

我有一个包含许多按钮的 HRMS 屏幕。我想根据更多功能对每个按钮进行分类,例如

出席-> 考勤标记 考勤登记表

离开-> 离开请求 离开OD授权 离开 OD 批准

其他-> 假期清单 留下余额

现在我的屏幕是这样的

我正在尝试实现可扩展列表视图。逻辑很简单,当单击子菜单时,我想转到与其关联的特定视图控制器。虽然我知道如何使用简单的表格视图来做到这一点

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)

我不知道如何在使用可扩展表格视图时实现它。我用谷歌搜索了相同的内容,但无法获得具体的解决方案。

【问题讨论】:

    标签: ios swift swift2


    【解决方案1】:

    你可以使用

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)
    {
        if (indexPath.section == 0)
        { 
            if (indexPath.row == 0)
            {
                /*The first row of the first section was tapped.
                  Put code here that you would like to execute when the
                  first row of the first section is tapped*/
            }
            if (indexPath.row == 1)
            {
                /*The second row of the first section was tapped.
                  Put code here that you would like to execute when the
                  second row of the first section is tapped*/
            }
        }  
    
        if (indexPath.section == 1)
        { 
            if (indexPath.row == 0)
            {
                /*The first row of the second section was tapped.
                  Put code here that you would like to execute when the
                  first row of the second section is tapped*/
            }
            if (indexPath.row == 1)
            {
                /*The second row of the second section was tapped.
                  Put code here that you would like to execute when the
                  second row of the second section is tapped*/
            }
        }  
    }
    

    可扩展的 tableView 与普通的 tableviews 相同。只需将您的代码在上述方法中为所需的 tableView 行调用 new viewController 即可。

    要记住的一件事是,当您使用多个部分时(如果您使用可扩展的 tableView,您将是这样),那么每个部分的行索引从零开始。

    例如,tableView 中有三个部分,每个部分包含三行,它们的索引将是这样的

    • 第 0 节

      • 第 0 行
      • 第 1 行
      • 第 2 行
    • 第 1 节

      • 第 0 行
      • 第 1 行
      • 第 2 行
    • 第 2 节

      • 第 0 行
      • 第 1 行
      • 第 2 行

    所以你需要检查 didSelectRowAtIndexPath 方法中的部分和行

    【讨论】:

    • 您能否详细说明当调用 didSelectRow AtIndexPath 方法时我们如何检查行和节
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2012-12-05
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多