Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我无法还原我取消选择的上一个单元格的属性_Ios_Swift_Uitableview_Tableview - Fatal编程技术网

Ios 我无法还原我取消选择的上一个单元格的属性

Ios 我无法还原我取消选择的上一个单元格的属性,ios,swift,uitableview,tableview,Ios,Swift,Uitableview,Tableview,我在MainstryBoard中有一个UIViewController,它包含一个tableview,它只显示标签,而不是令人兴奋的东西。当我点击其中一个单元格时,它会将我推到detailVC。问题从这里开始,当我从detailVC回来时,我推的单元格看起来仍然处于选中状态。而且看起来很恶心。我尽力了。最后,单元格是自定义单元格 注:我必须在这个项目中使用swift 2.3 func tableView(tableView: UITableView, cellForRowAtIndexPath

我在MainstryBoard中有一个UIViewController,它包含一个tableview,它只显示标签,而不是令人兴奋的东西。当我点击其中一个单元格时,它会将我推到detailVC。问题从这里开始,当我从detailVC回来时,我推的单元格看起来仍然处于选中状态。而且看起来很恶心。我尽力了。最后,单元格是自定义单元格

注:我必须在这个项目中使用swift 2.3

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableVieww.dequeueReusableCellWithIdentifier("cellNew", forIndexPath: indexPath) as! AltKategoriNewCell
        let data = self.katData[indexPath.row]
        cell.textLabelNew?.text = data["CatogryName"] as? String

        return cell
    }

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableVieww.dequeueReusableCellWithIdentifier("cellNew", forIndexPath: indexPath) as! AltKategoriNewCell
    let data = self.katData[indexPath.row]

    cell.textLabelNew?.text = data["CatogryName"] as? String

    cell.contentView.backgroundColor = UIColor.lightGrayColor()
    cell.backgroundColor = UIColor.lightGrayColor()
    cell.textLabelNew?.textColor = UIColor.blackColor()

    urunlerList.altKatDic = self.katData[indexPath.row]
    performSegueWithIdentifier("urunlerList", sender: nil)
}

 func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

    let cell = tableVieww.dequeueReusableCellWithIdentifier("cellNew", forIndexPath: indexPath) as! AltKategoriNewCell

    cell.contentView.backgroundColor = UIColor.whiteColor()
    cell.backgroundColor = UIColor.whiteColor()
    cell.textLabelNew?.textColor = UIColor.blackColor()
}
桌面视图

属性


错误的第一件事是,您正在didSelectRowAtIndexPath和didSelectRowAtIndexPath方法中对单元格进行排队。UITableView不希望您在那里这样做。如果需要在didSelectRowAtIndexPath中获取单元格,可以询问

 let cell = tableView.cellForRow(at: indexPath)
UITableViewCell已选择BackgroundView,UILabel具有highlightedTextColor。知道了这一点,您只需适当地设置单元格,就不需要在选择/取消选择时修改其属性,如下所示:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("cellNew", forIndexPath: indexPath) as! AltKategoriNewCell
    if nil == cell.selectedBackgroundView {
        cell.selectedBackgroundView = UIView()
        cell.selectedBackgroundView?.backgroundColor = UIColor.lightGrayColor()
    }
    let data = self.katData[indexPath.row]
    cell.textLabelNew?.text = data["CatogryName"] as? String

    return cell
}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    urunlerList.altKatDic = self.katData[indexPath.row]
    performSegueWithIdentifier("urunlerList", sender: nil)
}
这样,就可以删除didSelectRowAtIndexPath和didSelectRowAtIndexPath的实现