我觉得这是一个愚蠢的问题,但我不能让它工作。我希望有一个标题的单元匹配某个字符串。如果这个单元格匹配那个字符串,我希望单元格被突出显示。但是,当我运行我的应用程序时,单元格被选中(像普通表格视图中突出显示的灰色)一秒钟,然后消失。这是我的尝试。设置UITableViewCell在代码中选择
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCellWithIdentifier("RouteCell") as! UITableViewCell
var singleStop = self.stops[indexPath.row]
if(singleStop.stop_name == routeLabelName) // string comparison
{
cell.highlighted = true
cell.selected = true
}
cell.textLabel!.text = singleStop.stop_name
cell.imageView!.image = UIImage(named: "ArrowPathMiddle.png")
return cell
}
试试我的片段,我已经通过的Xcode 6.3.2 +迅速检查了它。它适用于我 – Doro