Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import UIKit
extension AgoraAudioViewController: UITableViewDelegate, UITableViewDataSource {
func createSpeakerTable() {
let newTable = UITableView()
self.view.addSubview(newTable)
newTable.frame = self.view.bounds
newTable.autoresizingMask = [.flexibleWidth, .flexibleHeight]
newTable.delegate = self
newTable.dataSource = self
newTable.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.speakerTable = newTable
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
section == 0 ? self.activeSpeakers.count : self.activeAudience.count
}
func numberOfSections(in tableView: UITableView) -> Int { 2 }
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
["Speakers", "Audience"][section]
}
func tableView(
_ tableView: UITableView, cellForRowAt indexPath: IndexPath
) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let cellUserID = Array(
indexPath.section == 0 ? self.activeSpeakers : self.activeAudience
)[indexPath.row]
cell.textLabel?.text = self.usernameLookups[cellUserID]
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment