2016-05-13 30 views
0

對不起,我真的找不到這個地方。如何將uitableviewcellselectionstyle.none設置爲靜態單元格?

我需要將我的選擇樣式設置爲none,以便在點擊它時行不會突出顯示。此外,我需要行可以選擇,因爲我有一些行需要擴展和摺疊。我知道這段代碼是UITableViewCellSelectionStyle.None,但我不知道我可以在哪裏實現它。謝謝!

編輯加入碼

 // MARK: - Table view data source 
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 1 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return 7 
} 

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 

    // Set height for date picker 

    if indexPath.section == 0 && indexPath.row == 2 { 
     let height:CGFloat = datePicker.hidden ? 0.0 : 216.0 
     return height 

    } 

    return super.tableView(tableView, heightForRowAtIndexPath: indexPath) 
} 

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

    // Expanding and collapsing date picker 
    UITableViewCellSelectionStyle.None 

    let datePickerIndexPath = NSIndexPath(forRow: 1, inSection: 0) 
    if datePickerIndexPath == indexPath { 

     datePicker.hidden = !datePicker.hidden 

     UIView.animateWithDuration(0.3, animations: {() -> Void in 
      self.tableView.beginUpdates() 
      // apple bug fix - some TV lines hide after animation 
      self.tableView.deselectRowAtIndexPath(indexPath, animated: true) 
      self.tableView.endUpdates() 
     }) 
    } 
} 

的代碼主要是針對我已實施的日期選擇器。一切正常,但單擊單元格會突出顯示默認選擇顏色的整行。

回答

1

很難知道哪裏能夠最好地實現它,而不需要看你的代碼,但是當你出隊/初始化你的單元格時,你肯定可以把它放在你的cellForRowAtIndexPath中。前return yourCell

+0

但目前我的表視圖數據源的代碼實際上是空的,因爲我使用的是靜態單元,實際上並沒有任何顯示。 也可以,'cellForRowAtIndexPath'可以用於靜態單元格嗎?我試過了,但是錯誤出現了 「終止應用程序,由於未捕獲異常'NSInternalInconsistencyException',原因:'無法使具有標識符TransportExpenseCell0的單元出列 - 必須爲標識符註冊一個nib或類或連接故事板中的原型單元格' 「 – Chris

+0

,我確實有一個靜態單元,其中帶有標識TransportExpenseCell0的靜態單元 – Chris

+0

剛添加在代碼 – Chris

0
cell.selectionStyle = .None 

只要打電話yourCell.selectionStyle = .None當你寫完相同的代碼(=),只需按點(。),因此,許多類型的功能將被彈出像這個 -

enter image description here

對於你的第二個問題,只需在數組中添加一些值來檢查工作是否正確。

+0

'dequeueReusableCellWithIdentifier'可以與靜態單元一起使用嗎?我收到錯誤「終止應用程序,由於未捕獲的異常'NSInternalInconsistencyException',原因:'無法將具有標識符TransportExpenseCell0的單元出列 - 必須爲該標識符註冊一個nib或類或連接故事板中的原型單元格' – Chris

相關問題