Ios detailtextlab是';未显示,但已100%设置

Ios detailtextlab是';未显示,但已100%设置,ios,xcode,swift,uitableview,custom-cell,Ios,Xcode,Swift,Uitableview,Custom Cell,我在我的tableView中添加了如下内容: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let reuseIdentifier = "Cell" var cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as! MGSw

我在我的tableView中添加了如下内容:

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

    let reuseIdentifier = "Cell"
    var cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as! MGSwipeTableCell!
    if cell == nil {

        cell = MGSwipeTableCell(style: UITableViewCellStyle.Default, reuseIdentifier: reuseIdentifier)
    }
    cell.delegate = self
    cell.backgroundColor = blue
}
一切正常。但是现在如果我点击单元格,单元格的颜色可能会先变为白色,然后变为绿色(默认颜色为蓝色)。如果按下单元格,则会发生以下情况:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  let mySelectedCell = tableView.cellForRowAtIndexPath(indexPath) as! MGSwipeTableCell!
  mySelectedCell.backgroundColor = green
  mySelectedCell.detailTextLabel?.text = "Test" 
}
因此,颜色应仅更改为绿色,而不是白色,然后更改为绿色,并应显示带有文本“Test”的detailTextLabel。 我希望你能帮我解决这个问题。我真的不知道该怎么办

解决方案:

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

let reuseIdentifier = "Cell"
    var cell =  tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as! MGSwipeTableCell!
    cell = MGSwipeTableCell(style: UITableViewCellStyle.Subtitle,  reuseIdentifier: reuseIdentifier)
    cell.selectionStyle = UITableViewCellSelectionStyle.None
    cell.delegate = self
    cell.backgroundColor = blue

}
保留“DidSelectRowatineXpath”中的所有内容


将“DidSelectRowatineDxPath”中的所有内容保持原样

在何处以及如何创建在
tableView(tableView:UITableView,CellForRowatineDxPath indexPath:NSIndexPath)中使用的
mySelectedCell
对象
?UITableViewCellStyle.Default没有字幕。您必须使用.Value1、.Value2或.Subtitle,具体取决于您希望手机的外观@alex_p是我的错,我应该是手机而不是我选择的手机。我更新了问题。@Tyrelidrel没有帮助。我尝试了所有3种样式,但仍然不起作用。
Selection
字段在故事板的
属性检查器中的自定义单元格中的值是多少?在哪里以及如何创建
mySelectedCell
对象,您在
tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)中使用该对象
?UITableViewCellStyle.Default没有字幕。您必须使用.Value1、.Value2或.Subtitle,具体取决于您希望手机的外观@alex_p是我的错,我应该是手机而不是我选择的手机。我更新了问题。@Tyrelidrel没有帮助。我尝试了所有3种样式,但仍然不起作用。
选择
字段在故事板的
属性检查器
中的自定义单元格中的值是多少?非常感谢您的帮助!现在,颜色的更改可以正常工作,但detailTextLabel仍然没有显示。在“didSelectRowAtIndexPath”中,能否在“mySelectedCell.backgroundColor=green”之后设置断点,然后在控制台中设置“po mySelectedCell.detailedTextLabel”?我在cellForRowAtIndexPath函数中解决了这个问题(请参阅我的问题)。谢谢你的帮助!很好,没问题:非常感谢你的帮助!现在,颜色的更改可以正常工作,但detailTextLabel仍然没有显示。在“didSelectRowAtIndexPath”中,能否在“mySelectedCell.backgroundColor=green”之后设置断点,然后在控制台中设置“po mySelectedCell.detailedTextLabel”?我在cellForRowAtIndexPath函数中解决了这个问题(请参阅我的问题)。谢谢你的帮助!很好,没问题:D
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let reuseIdentifier = "Cell"
var cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as! MGSwipeTableCell!
if cell == nil {
    //Change this line
    cell = MGSwipeTableCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
}
//And this line
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.delegate = self
cell.backgroundColor = blue
}