2017-06-17 51 views
0

我在mainstoryboard中有一個UIViewController,它包含一個tableview,它只是顯示標籤,而不是令人興奮的東西。當我點擊其中一個單元格時,它會將我推向detailVC。問題從這裏開始,當我從detailVC返回時,我推送的單元格仍然在選擇中。它看起來很嚴重。我盡我所能去嘗試。最後細胞是定製細胞。我無法恢復我取消選擇的前一個單元格的屬性

P.s .:我必須在這個項目中使用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() 
} 

的TableView TableView

屬性

enter image description here

回答

1

這是錯誤的第一件事是,你出列的單元格中didSelectRowAtIndexPathdidDeselectRowAtIndexPath方法。 UITableView並不指望你那樣做。如果你需要得到didSelectRowAtIndexPath細胞,你可以問

let cell = tableView.cellForRow(at: indexPath) 

UITableViewCellselectedBackgroundView和,UILabelhighlightedTextColor。知道了,你可以設置相應的單元格,然後你就不會需要修改它在選擇/取消的屬性,如:

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) 
} 

到這一點,你的didSelectRowAtIndexPathdidDeselectRowAtIndexPath實現可以被移除。

相關問題