今天来加入更多的Dependencies,以及聊天开发的准备
那麽我们先来新增引用的函式库。
在Podfile新增以下的指令,然後下载。
pod 'MessageKit'
pod 'JGProgressHUD'
pod 'RealmSwift'
pod 'SDWebImage'
先确认此时专案是可以complie的!
接着我们在对话的画面新增tableView
private let tableView: UITableView = {
let table = UITableView()
table.isHidden = true // hide when there's no conversation
table.register(UITableViewCell.self,
forCellReuseIdentifier: "cell")
return table
}()
当没有对话可以显示的时候,我们将画面的table view藏起来,并放上noConversationLabel作为提示画面。
private let noConversationLabel: UILabel = {
let label = UILabel()
label.text = "No conversations yet."
label.textAlignment = .center
label.textColor = .gray
label.font = .systemFont(ofSize: 21, weight: .medium)
label.isHidden = true
return label
}()
接着在view load进来的时候,把sub view放到stake中
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tableView)
view.addSubview(noConversationLabel)
setupTableView()
fetchConversations()
}
private func setupTableView() {
tableView.delegate = self
tableView.dataSource = self
}
private func fetchConversations() {
tableView.isHidden = false
}
前几次文章有提到,我们在进行table view或是各种元件的呈现,会需要指派一个对象,此时我们将此对象指派给自己,不过就需要加上继承,因为目前UITableView无法作为指派的对象。
而我们也提过,与主要逻辑无关的程序结构,可以另外使用extension来撰写。
extension ConversationViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "Hello world"
cell.accessoryType = .disclosureIndicator // ">" at the right
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let vc = ChatViewController()
vc.title = "Jenny Smith"
vc.navigationItem.largeTitleDisplayMode = .never
navigationController?.pushViewController(vc, animated: true)
}
}
在此,转换後的charViewController,因为还没有资料跟画面,我们先个假资料XD
好的!那今天就到这边,有比前几天的进度好一些些><
若上述内容有误或可以改进的部分,欢迎留言以及提出任何指教~
谢谢 (´・∀・`)
<<: [Day 21] - 『转职工作的Lessons learned』 - GraphQL (Hasura) - Event Trigger
作业系统 前九天的内容大致上是我在Day1提到的扫盲课程学到的东西,当时我使用的是一台Windows...
今次参与战斗是为了挑战自我。 在生活中挤出时间,利用下班的时间好好充实自己。 在加入新团队後,con...
Download free KingRoot App for your Smartphone tha...
温馨回顾 在前一篇我们有简单介绍了 Sign in with Apple 是什麽,有哪些使用限制 以...
在部署基於容器的应用程序时,我们可以使用容器编排器来配置和管理容器。这意味着变更请求已获批准和实施,...