【发布时间】:2011-05-18 11:26:30
【问题描述】:
在我的tableview中,名称和标题是通过xml解析来自服务器的,如下图。
在这个 tableview 列表中,我想使用如下图所示的索引搜索。我该怎么做?
【问题讨论】:
-
您可能需要使用 searchBox 进行字母匹配搜索,并且应该显示该特定数组
标签: iphone uitableview
在我的tableview中,名称和标题是通过xml解析来自服务器的,如下图。
在这个 tableview 列表中,我想使用如下图所示的索引搜索。我该怎么做?
【问题讨论】:
标签: iphone uitableview
您可以拥有字典数组,其中每个部分将由字典对象表示。字典的键是节标题,值是节中的行数组。
您可以使用 NSPredicate 从服务器搜索返回的数组并构造数据源数组。 NSPredicate Programming Guide
【讨论】:
var arrData = Array<Any>()
var fromFilter:Bool = false
var arrStrData = Array<String>()
步骤 - 1: 在您的故事板中创建 UItableView。 - 数据源,委托
步骤 - 2: 导入 - UITableViewDelegate,UITableViewDataSource
第 3 步:实施方法
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.arr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "MainCell") as! MainCell
cell.selectionStyle = .none
var dictData: [String: AnyObject] = [String: AnyObject]()
dictData = self.arrData[indexPath.row] as! [String : AnyObject]
cell.lblName.text = dictData["name"] as? String ?? ""
cell.lblEmail.text = dictData["email"] as? String ?? ""
cell.lblAddress.text = dictData["address"] as? String ?? ""
let image = dictData[""] as? String ?? ""
cell.img?.sd_setImage(with: URL(string: image), placeholderImage: UIImage(named: "download.jpeg"), options: [.continueInBackground,.lowPriority], completed: {(image,error,cacheType,url) in
if error == nil
{
cell.img?.image = image
}
else
{
cell.img?.image = UIImage(named: "download.jpeg")
}
})
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
【讨论】: