2016-07-29 3 views

Antwort

2

Zunächst mit dem Storyboard hier beginnt die Hierarchie von TableViewController. Siehe das Bild unten.

enter image description here

danach eine UITableViewCell Klasse Erstellen der zweite Tabellendarstellung zu halten, und diese Klasse zweite Tabelle Sichtzelle zuordnen. wie nachstehend.

import UIKit 
class tableTableViewCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet weak var tableView: UITableView! 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
     tableView.delegate = self 
     tableView.dataSource = self 
    } 

    override func setSelected(selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 

     // Configure the view for the selected state 
    } 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 5 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("dynamicCell")! 
     cell.textLabel?.text = "\(indexPath.row)" 
     return cell 
    } 
} 

enter image description here

und dann in Tableviewcontroller cellForRow Verfahren sowohl die Zelle initialisieren und die Zelle zurück, wie erforderlich.

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

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    if indexPath.row == 0 { 
     return 50 
    } else { 
     return 200 
    } 
} 


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    if indexPath.row == 0 { 

     let cell = tableView.dequeueReusableCellWithIdentifier("staticCell", forIndexPath: indexPath) 
     return cell 
    } else { 
     let cell = tableView.dequeueReusableCellWithIdentifier("tableCell")! as! tableTableViewCell 
     return cell 
    } 

    // Configure the cell... 
} 

Das ist es. Bitte schön. Hier ist die Ausgabe des obigen Codes.

enter image description here

Man kann sehen, dass zuerst „Zelle 1“ ist eine statische Zelle und unter dem in die zweite Zelle ein weiterer tableview zeigt die Zahl von 0-4 bedeutet, eine andere Zelle 5 der zweiten Zelle 2 in tableview

+0

Entschuldigung für lange nehmen, um dies als die richtige Antwort zu markieren. musste es testen, bevor ich markiere - und es funktioniert wie Charme. Vielen Dank für Ihre Zeit und für die sehr gute Antwort post :) – MarkosDarkin

+0

Ihre Begrüßung :) –

Verwandte Themen