2016-03-08 114 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