2016-04-26 14 views
0

Ich habe versucht, die erweiterbaren Tabellenansicht Zellen mit dieser tutorialErweiterbare Tabellenansicht Zelle mit Auto-Layout funktioniert nicht?

replizieren Ich werde zeigen, was ich getan habe und darauf hinweisen, was fehlen mir hier? !! Ich stecke hier fest. Es wäre hilfreich, wenn Sie auf den Schritt hinweisen, den ich vermisse !!

Tableviewcontroller

class ExpandableCell: UITableViewController { 

let titles = ["one" , "two"]  

override func viewDidLoad() { 
    super.viewDidLoad() 

    tableView.rowHeight = UITableViewAutomaticDimension 
    tableView.estimatedRowHeight = 125 
// tableView.tableFooterView = UIView(frame: CGRectZero) 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return titles.count 
} 

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableCell 

    cell.title.text = titles[indexPath.row] 
    cell.indexPath = indexPath 


    switch expandedIndexPath { 
    case .Some(let expandedIndexPath) where expandedIndexPath == indexPath: 
     cell.showsDetails = true 
    default: 
     cell.showsDetails = false 
    } 

    return cell 

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

    tableView.deselectRowAtIndexPath(indexPath, animated: false) 

    switch expandedIndexPath { 
    case .Some(_) where expandedIndexPath == indexPath: 
     expandedIndexPath = nil 
    case .Some(let expandedIndex) where expandedIndex != indexPath: 
     expandedIndexPath = nil 
     self.tableView(tableView, didSelectRowAtIndexPath: indexPath) 
    default: 
     expandedIndexPath = indexPath 
    } 

} 

var expandedIndexPath: NSIndexPath? { 
    didSet { 
     switch expandedIndexPath { 
     case .Some(let index): 
      tableView.reloadRowsAtIndexPaths([index], withRowAnimation: UITableViewRowAnimation.Automatic) 
     case .None: 
      tableView.reloadRowsAtIndexPaths([oldValue!], withRowAnimation: UITableViewRowAnimation.Automatic) 
     } 
    } 
    } 
} 

TableViewCell

class TableCell: UITableViewCell { 

@IBOutlet weak var title: UILabel! 
@IBOutlet weak var descriptionConstraint: NSLayoutConstraint! 
@IBOutlet weak var descriptionNew: UILabel! 

// let detailViewDefaultHeight: CGFloat = 44 
let lowLayoutPriority: Float = 250 
let highLayoutPriority: Float = 999 


var showsDetails = false { 
    didSet { 
     descriptionConstraint.priority = showsDetails ? lowLayoutPriority : highLayoutPriority 
    } 
} 

var indexPath = NSIndexPath() 

override func awakeFromNib() { 
    super.awakeFromNib() 
    descriptionConstraint.constant = 0 
    } 
} 

Storyboard

enter image description here

Diese

ist die Ausgang Ich erhalte das ist nicht das, was ich bin versucht zu bekommen,

enter image description here

+0

und was th gesetzt haben e Frage ??? –

+0

Es wird nur eine Tabelle mit den Titel- und Beschreibungsbezeichnungen angezeigt, aber nicht die beabsichtigte Ausgabe !! –

Antwort

0

Base auf Ihren Code Ich denke, fehlen Sie brüll Methode: -

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
    { 
     return UITableViewAutomaticDimension 
    } 
+0

Das Hinzufügen dieser Funktion hilft nicht !! Sie könnten das erwähnte Tutorial beziehen und mir helfen, das Problem zu lösen. –

0

Scheint, wie Sie die niedrigen und hohen Prioritätswerte in der umgekehrten Reihenfolge

var showsDetails = false { 
    didSet { 
     descriptionConstraint.constant = showsDetails ? highLayoutPriority: lowLayoutPriority 
    } 
} 
+0

Die Reihenfolge ist korrekt, wenn ich es ändere, wird es nicht erweitert. Trotzdem danke für den Vorschlag. Ich habe es herausgefunden!! –

+0

Sie sollten die Lösung als eine Antwort für zukünftige Leser hinzufügen. – UditS