2016-03-08 117 views
1

所以基本上我实现了一个静态表到目前为止,非常的我想补充另一个动态表该事件的参与者列表的底部。看看这里的截图:静态表视图(小区)内实现一个动态表

Screenshot of my Xcode project

我现在的问题是,我是不能够建立一个自己的类这是在过去的静态表格视图单元格放置成动态表。您可以在截图中查看红色标记的方格。我的实际计划是给动态一个自己的类,然后检索参与者列表作为一个数组,并根据数组的数量设置numberOfRowsInSection等。

你们有一个想法,我可以如何实现静态表?所以基本上我可以如何在底部添加动态表格,包括以后的无尽滚动?

我已经尝试过这篇文章,但它并没有完全帮助我:Dynamic UITableView inside static cell 我会在下面添加我的解决方案。

您的帮助将不胜感激!

亲切的问候 马特

+1

[动态静态细胞内的UITableView]的可能的复制(HTTP:/ /stackoverflow.com/questions/20777878/dynamic-uitableview-inside-static-cell) – JAL

回答

0

好的,谢谢rMickeyD的提示。我部分使用它并实现它。你可以看到这个截图这里的结果:

Storyboard

添加到这一点,我设置了静态表使细胞与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 
    } 
} 
1

创建一个视图控制器。然后将两个ContainerViewController放置在ViewController中。使用嵌入创建segues到2个独立的tableView控制器。一个用于静态tableview,另一个用于动态tableview。这样你可以在上面有一个静态表,下面是一个动态表。

+0

嘿rMickeyD,谢谢你的回复。我找到了解决方案,你帮助我的文章。 – Mattk90

2

除非有真正的理由让顶端部分成为表格,否则最简单的解决方案是将顶端部分设为表头视图并使用动态表格。

+0

THX U,你节省了我的时间! – user3722523