【问题标题】:Perform action in TagViews inside UITableViewCell在 UITableViewCell 内的 TagViews 中执行操作
【发布时间】:2020-02-05 07:27:48
【问题描述】:

我正在使用 TaglistView 在 UITableViewCell 中显示标签。 https://github.com/ElaWorkshop/TagListView

现在需要获取在特定索引路径上选择的标签的 id。

例如:JSON 数组的格式为:

索引 0 : [{ name: "abc", 值:“11” },{ 名称:“c”, 值:“12”}]

索引 1 : [{ name: "abcd", 值:“21” },{ 名称:“abcde”, 值:“22” }]

索引 2 : [{ name: "abcde", 值:“31” },{名称:“abcde”, 值:“32” }]

我用来添加标签列表的代码:

func configureCell (tableView: UITableView, cell: PlaylistCell, indexPath: IndexPath){

        // Setup TagView
        cell.tagListView.removeAllTags()
        for tag in array?[indexPath.row].sponsoredBy ?? [] {
            cell.tagListView.addTag(tag.name ?? "")
        }
        cell.tagListView.delegate = self


    }

现在 Taglist 委托方法:

func tagPressed(_ title: String, tagView: TagView, sender: TagListView) {
        print("Tag pressed: \(title)")
    }

我正在按下标签的名称,但需要获得相同的值。

【问题讨论】:

    标签: ios swift taglist


    【解决方案1】:

    您可以使用indexPath.rowtagListView 分配标签,就像在cellForRow 中一样

    tagListView.tag == indexPath.row
    

    现在 Taglist 委托方法:

    func tagPressed(_ title: String, tagView: TagView, sender: TagListView) {
        let yourObject = yourArrayOfTagListContainer[tagView.tag]
    
        print("Tag pressed: \(yourObject.value)")
    }
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2016-03-26
      • 1970-01-01
      • 2015-04-09
      • 2017-09-23
      • 1970-01-01
      • 2021-12-14
      • 2018-01-25
      • 2013-06-24
      • 1970-01-01
      相关资源
      最近更新 更多