2016-05-13 52 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

相关问题