2015-11-16 3 views
1

У меня есть MGSwipeTableCell добавляемые в моем Tableview так:detailTextLabel не отображается, но 100% установить

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

Так что цвет должен измениться только на зеленый, не белый, а затем в зеленый и detailTextLabel с текстом «Test» должен отображаться. Надеюсь, вы поможете мне решить эту проблему. Я действительно не знаю, что делать.

Решение:

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 

} 
+0

Где и как вы создаете 'объект mySelectedCell', который используется в' Tableview (Tableview: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) '? –

+0

UITableViewCellStyle.Default не имеет субтитров. Вы должны использовать .Value1, .Value2 или .Subtitle в зависимости от того, как вы хотите, чтобы ваша камера выглядела. https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/c/tdef/UITableViewCellStyle – Tyrelidrel

+0

@alex_p Это была моя ошибка, я должен быть ячейкой вместо mySelectedCell. Я обновил вопрос. – 123

ответ

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

оставить все как есть внутри "didSelectRowAtIndexPath"

+0

Большое спасибо за вашу помощь! Теперь изменение цвета работает, но detailTextLabel все еще не отображается. – 123

+0

в «didSelectRowAtIndexPath», может ли поставить точку останова после «mySelectedCell.backgroundColor = зеленый», а затем в консоли «po mySelectedCell.detailedTextLabel»? –

+0

Я решил это в функции cellForRowAtIndexPath (см. Мой вопрос). Спасибо за вашу помощь! – 123

 Смежные вопросы

  • Нет связанных вопросов^_^