好的,謝謝rMickeyD的提示。我部分使用它並實現它。你可以看到這個截圖這裏的結果:
添加到這一點,我設置了靜態表使細胞與prepareToSegue的高度與guests.count的數組* 44單元格高度在右邊。
代碼的靜態表視圖(左):
import UIKit
class EventDetailTableViewController: UITableViewController {
var attendeesArrayFromDatabase = ["Kathi", "Cansin", "Tyrone", "Manuel", "Stavros", "Christoph", "Maria", "Aditya", "Kathi", "Cansin", "Tyrone", "Manuel", "Stavros", "Christoph", "Maria", "Aditya"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 1 && indexPath.row == 0 {
let height:CGFloat = CGFloat(attendeesArrayFromDatabase.count * 44)
return height
}
return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}
// MARK: Navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destViewController : EventPeopleJoinedContainerTableViewController = segue.destinationViewController as! EventPeopleJoinedContainerTableViewController
destViewController.attendeesArray = attendeesArrayFromDatabase
}
}
和用於動態表右邊的tableview:
import UIKit
class EventPeopleJoinedContainerTableViewController: UITableViewController {
var attendeesArray = []
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return attendeesArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("personJoined", forIndexPath: indexPath) as UITableViewCell
//Create a label with the name of a person from array attendeesArray
let attendeeNameLabel = UILabel(frame: CGRect(x: 70, y: 0, width: cell.frame.width, height: cell.frame.height))
attendeeNameLabel.font = cell.textLabel?.font.fontWithSize(14.0)
attendeeNameLabel.textColor = UIColor.darkGrayColor()
attendeeNameLabel.text = attendeesArray[indexPath.row] as? String
//Create a image view for the profile picture of the guest
let attendeeImageView = UIImageView(frame: CGRect(x: 25, y: 7, width: 30, height: 30))
attendeeImageView.layer.cornerRadius = attendeeImageView.frame.size.width/2
attendeeImageView.layer.borderColor = UIColor.whiteColor().CGColor
attendeeImageView.layer.borderWidth = 0.5
attendeeImageView.clipsToBounds = true
attendeeImageView.image = UIImage(named: "profilPicDummy")
cell.contentView.addSubview(attendeeNameLabel)
cell.contentView.addSubview(attendeeImageView)
return cell
}
}
[動態靜態細胞內的UITableView]的可能的複製(HTTP:/ /stackoverflow.com/questions/20777878/dynamic-uitableview-inside-static-cell) – JAL