你只需要搜索的目的和显示所有数据的一个的tableView。只需维护两个数组。第一个包含您的原始数据,第二个包含搜索的数据。作为一个时候搜索开始重新加载tableView与第二阵列,并把所有的数据在其中。像这样你的导航将适用于这两种情况。
斯威夫特:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
if isSearch == "true"
{
return self.searchArray.count
}
else
{
return self.arr1.count
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell:UITableViewCell? =
tableView.dequeueReusableCellWithIdentifier("tableCell") as? UITableViewCell
if(cell == nil)
{
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "tableCell")
cell!.selectionStyle = UITableViewCellSelectionStyle.None
}
if isSearch == "true"
{
var main_string = self.searchArray[indexPath.row]
var attributedString = NSMutableAttributedString(string:main_string)
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor(red: 0.0/255.0, green: 168.0/255.0, blue: 255.0/255.0, alpha: 1.0) , range: NSMakeRange(0, string_to_color.length))
name.attributedText = attributedString
}
else
{
name.text = self.arr1[indexPath.row] as String
}
return cell!
}
请张贴代码只要你有要求人们调试代码的问题。 – PengOne 2011-05-31 17:44:24
如果它崩溃,请添加崩溃日志。 – 2011-05-31 17:50:16