在 UITableViewCell 中的 TagViews 中执行操作
Perform action in TagViews inside UITableViewCell
我正在使用 TaglistView 在 UITableViewCell 中显示标签。 https://github.com/ElaWorkshop/TagListView
现在需要获取在特定索引路径上选择的标签的 ID。
例如:JSON 数组的格式为:
索引 0:[{名称:"abc",
值:“11”
},{ 名称: "c",
值:“12”}]
索引 1:[{名称:"abcd",
值:“21”
},{ 姓名: "abcde",
值:“22”
}]
索引 2:[{名称:"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)")
}
我正在按下标签的名称,但需要获取相同的值。
您可以使用 indexPath.row
将标签分配给 tagListView
,就像在 cellForRow
中一样
tagListView.tag == indexPath.row
现在 Taglist 委托方法:
func tagPressed(_ title: String, tagView: TagView, sender: TagListView) {
let yourObject = yourArrayOfTagListContainer[tagView.tag]
print("Tag pressed: \(yourObject.value)")
}
希望对您有所帮助
我正在使用 TaglistView 在 UITableViewCell 中显示标签。 https://github.com/ElaWorkshop/TagListView
现在需要获取在特定索引路径上选择的标签的 ID。
例如:JSON 数组的格式为:
索引 0:[{名称:"abc", 值:“11” },{ 名称: "c", 值:“12”}]
索引 1:[{名称:"abcd", 值:“21” },{ 姓名: "abcde", 值:“22” }]
索引 2:[{名称:"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)")
}
我正在按下标签的名称,但需要获取相同的值。
您可以使用 indexPath.row
将标签分配给 tagListView
,就像在 cellForRow
tagListView.tag == indexPath.row
现在 Taglist 委托方法:
func tagPressed(_ title: String, tagView: TagView, sender: TagListView) {
let yourObject = yourArrayOfTagListContainer[tagView.tag]
print("Tag pressed: \(yourObject.value)")
}
希望对您有所帮助