【问题标题】:UItableview section selected - swift选择 UItableview 部分 - 快速
【发布时间】:2017-02-21 06:14:10
【问题描述】:

''Hello World'' :) 我有一个包含 4 个不同部分的 UItableview。我正在尝试根据所选部分用一些行填充每个部分。我努力 -__- 检测选择了哪个部分以便相应地填充它们。 In my program I have created 4 uibuttons (outside of the tableview and they represents each user; when a button is selected I use them to name the section header).现在我想将选择的按钮与该部分链接。 应该如何继续知道选择了哪个部分。如果选择了按钮 A,则表示选择了第 0 节,然后在第 0 节中执行 x 操作(例如插入新行); 如果选择按钮 B(即选择第 1 节)然后执行操作 y 等等...

提前感谢你帮助一个绝望的灵魂

【问题讨论】:

    标签: ios swift uitableview


    【解决方案1】:

    为按钮设置标签。

    button1.tag = 0
    button2.tag = 1
    button3.tag = 2
    button4.tag = 3
    

    然后添加目标

    button1.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
    button2.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
    button3.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
    button4.addTarget(self, action: #selector(didTouchButton(_:)), for: .touchUpInside)
    

    然后按钮何时会选择检查发件人标签并对部分进行操作

    func didTouchButton(_ sender: UIButton) {
        let section = sender.tag
    
        //do operations in section
    }
    

    Here 是基于节索引在节中插入和删除行的示例。在 Swift3 中,您应该基于以下方法:

    func insertRows(at: [IndexPath], with: UITableViewRowAnimation)
    func deleteRows(at: [IndexPath], with: UITableViewRowAnimation)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      相关资源
      最近更新 更多