如何在使用uisearchbar搜索后获取索引节标题 和委托和SQL查询 例如,我有一个表显示所有联系人与第一个字符的节标题现在在搜索栏上绑定文本后,匹配列表应该是dipslayed结果匹配节标题标题作为我尝试与代表的第一个字符。 `func getfirstcharacter() { firstchar.removeAll()
let (resultSet, err) = SD.executeQuery("SELECT DISTINCT(SUBSTR(name, 1, 1)) AS indexChar FROM tablename ORDER BY indexChar")
if err == nil && resultSet.count > 0
{
for row in resultSet
{
firstchar.append((row["indexChar"]?.asString()!)!)
}
}
}
答案 0 :(得分:0)
func getsearchfirstcharacter()
{
firstchar.removeAll()
let (resultSet, err) = SD.executeQuery("SELECT DISTINCT(SUBSTR(name, 1, 1)) AS indexChar FROM tablename where name like '%\(srchSearchBar.text!)%' ORDER BY indexChar")
if err == nil && resultSet.count > 0
{
for row in resultSet {
firstchar.append((row["indexChar"]?.asString()!)!)
}
}
}
只需将上面提到的查询和iboutlet替换为搜索栏,然后输入输入的文本并运行查询