1

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

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

例如:JSON 数组的格式为:

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

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

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

我用于添加 taglist 的代码:

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)")
    }

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

4

1 回答 1

4

您可以在 cellForRow 中将标签tagListView分配给likeindexPath.row

tagListView.tag == indexPath.row

现在 Taglist 委托方法:

func tagPressed(_ title: String, tagView: TagView, sender: TagListView) {
    let yourObject = yourArrayOfTagListContainer[tagView.tag]

    print("Tag pressed: \(yourObject.value)")
}

希望能帮助到你

于 2020-02-05T07:35:59.123 回答