代码之家  ›  专栏  ›  技术社区  ›  Ahmad Taalab

基于所选内容在表视图中显示/隐藏节

  •  0
  • Ahmad Taalab  · 技术社区  · 6 年前

    我正在开发ipad应用程序,这个资产申请应用程序, 我有6个复选框和表格视图,如图像

    我在表中创建了6个部分,当用户在表视图中选择“Ex Laptop”时,只会显示“Laptop”部分,其他部分将被删除或隐藏。 这是我的密码

    @objc func circleBoxValueChanged(sender:checkbox){
    tblview.ishidden=假
    
    
    开关发送器.tag{
    案例1:
    打印(“1”)
    案例2:
    打印(“2”)
    案例3:
    打印(“3”)
    案例4:
    打印(“4”)
    案例5:
    打印(“5”)
    案例6:
    打印(“6”)
    违约:
    打破
    }
    print(“圆盒值更改:\(sender.ischecked)”)
    }
    
    
    //标记:—TableView委托
    func tableview(u tableview:uitableview,heightforrowat indexpath:indexpath)->cgfloat{
    返回200
    }
    
    func numberofsections(在TableView:uiTableView中)->int{
    返回6
    }
    func tableview(u tableview:uitableview,titleforheaderinsection部分:int)->字符串?{
    如果截面==0{
    返回“笔记本电脑”
    }否则,如果截面==1{
    返回“移动”
    }否则,如果截面==2{
    返回“前徽章”
    }
    否则,如果截面==3{
    返回“VIP徽章”
    }
    否则,如果截面==4{
    返回“礼物”
    }
    否则,如果截面==5{
    返回“储物柜”
    }否则{
    
    返回“其他”
    
    }
    }
    func tableview(uTableView:uiTableView,numberofRowsPreagon部分:int)->int{
    如果截面==0{
    返回1
    
    }否则,如果截面==1{
    返回1
    
    }否则,如果截面==2{
    返回1
    
    }否则,如果截面==3{
    返回1
    
    }否则,如果截面==4{
    返回1
    
    }否则,如果截面==5{
    返回1
    
    }否则{
    返回0
    
    }
    }
    func tableview(u tableview:uitableview,cellforrowat indexpath:indexpath)->uitableviewcell{
    开关indexpath.section{
    案例0:
    让cell1=tableview.dequeuerusablecell(withIdentifier:“cell1”,for:indexpath)作为!笔记本电脑移动可视手机
    返回单元格1
    
    案例1:
    让cell1=tableview.dequeuerusablecell(withIdentifier:“cell1”,for:indexpath)作为!笔记本电脑移动可视手机
    返回单元格1
    
    案例2:
    让cell1=tableview.dequeuerusablecell(withIdentifier:“cell2”,for:indexpath)作为!其他要求表格视图单元格
    返回单元格1
    
    案例3:
    让cell1=tableview.dequeuerusablecell(withIdentifier:“cell2”,for:indexpath)作为!其他要求表格视图单元格
    返回单元格1
    案例4:
    让cell1=tableview.dequeuerusablecell(withIdentifier:“cell2”,for:indexpath)作为!其他要求表格视图单元格
    返回单元格1
    
    案例5:
    让cell1=tableview.dequeuerusablecell(withIdentifier:“cell2”,for:indexpath)作为!其他要求表格视图单元格
    返回单元格1
    
    
    违约:
    让cell1=tableview.dequeuerusablecell(withIdentifier:“cell2”,for:indexpath)作为!其他要求表格视图单元格
    返回单元格1
    
    }
    
    
    
    }
    < /代码> 
    
    

    你能帮我吗enter image description here

    我在表中创建了6个部分,当用户在表视图中选择“Ex Laptop”时,只会显示“Laptop”部分,其他部分将被删除或隐藏。 这是我的密码

    @objc func circleBoxValueChanged(sender: Checkbox) {
        tblView.isHidden = false
    
    
        switch sender.tag {
        case 1:
            print("1")
        case 2:
            print("2")
        case 3:
            print("3")
        case 4:
            print("4")
        case 5:
            print("5")
        case 6:
            print("6")
        default:
            break
        }
        print("circle box value change: \(sender.isChecked)")
    }
    
    
    // MARK: - TableView Delegate
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 200
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 6
    }
    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        if section == 0 {
            return "Laptop"
        }else if section == 1 {
            return "Mobile"
        }else if section == 2 {
            return "Ex Badge"
        }
        else if section == 3 {
            return "VIP Badge"
        }
        else if section == 4 {
            return "Gift"
        }
        else if section == 5{
            return "Locker"
        }else{
    
            return "Other"
    
        }
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 1
    
        }else if section == 1{
            return 1
    
        }else if section == 2{
            return 1
    
        }else if section == 3{
            return 1
    
        }else if section == 4{
            return 1
    
        }else if section == 5{
            return 1
    
        }else{
            return 0
    
        }
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
        switch indexPath.section {
        case 0:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! laptop_MobileTableViewCell
            return cell1
    
        case 1:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! laptop_MobileTableViewCell
            return cell1
    
        case 2:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
            return cell1
    
        case 3:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
            return cell1
        case 4:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
            return cell1
    
        case 5:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
            return cell1
    
    
        default:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
            return cell1
    
        }
    
    
    
    }
    

    你能帮助我吗

    1 回复  |  直到 6 年前
        1
  •  1
  •   Shehata Gamal    6 年前

     struct Item {
    
       var name:String
    
       var isShown:Bool
    }
    
    let arr = [Item(name:"LapTop",isShown:true)] // and so--on
    

    numberOfSections

    return arr.filter {$0.isShown}.count
    

    titleForHeader

    return arr.filter{$0.isShown}[indexPath.section].name